Skip to content

Instantly share code, notes, and snippets.

@ntakouris
Created July 18, 2019 09:02
Show Gist options
  • Save ntakouris/5a707838231285a349c5646d8dd06099 to your computer and use it in GitHub Desktop.
Save ntakouris/5a707838231285a349c5646d8dd06099 to your computer and use it in GitHub Desktop.
[HttpPost(ApiRoutes.Posts.Create)]
public Task<IActionResult> Create([FromBody] Post post)
{
if (string.IsNullOrEmpty(post.Id)
post.Id = Guid.NewGuid().ToString();
_posts.AddPost(post);
var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
var locationUri = baseUrl + "/" + ApiRoutes.Posts.Get.Replace("{postId}", post.Id.ToString());
return Created(locationUri, post);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment