Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NServiceBus Cosmos Sample - Add API
app.MapPost("/create", async (IMessageSession messageSession, [FromBody] Post post) =>
{
var addPostCommand = new Messages.AddPost(post.Title, post.Description, post.Author);
await messageSession.Send(addPostCommand);
return Results.Accepted(null, new { addPostCommand.PostId });
});
app.MapPost("/add-comment", async (IMessageSession messageSession, [FromBody] Comment comment) =>
{
var addCommentCommand = new Messages.AddComment(comment.PostId, comment.Content, comment.CommentBy);
await messageSession.Send(addCommentCommand);
return Results.Accepted(null, new { addCommentCommand.CommentId });
});
app.Run();
public record Post(string Title, string Description, string Author);
public record Comment(string PostId, string Content, string CommentBy);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment