Skip to Content
Building RESTful Web Services with .NET Core
book

Building RESTful Web Services with .NET Core

by Gaurav Aroraa, Tadit Dash
May 2018
Intermediate to advanced
334 pages
7h 25m
English
Packt Publishing
Content preview from Building RESTful Web Services with .NET Core

POST

POST is used to create a resource. In our case, we will try to create a product using a POST request to the server. Before doing that, we will make a few changes to our project. You can find all related code on GitHub (https://github.com/PacktPublishing/Building-RESTful-Web-services-with-DOTNET-Core), so don't worry at all!

Why wait then? Let's write the Post method as follows:

 // POST: api/Products[HttpPost]public async Task<IActionResult> Post([FromBody]Product product)  => (await _productService.CreateProductAsync(product))    ? (IActionResult)Created($"api/products/{product.Id}", product) // HTTP 201    : StatusCode(500); // HTTP 500

The action method calls CreateProductAsync of the related service and checks if the operation was successful. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On RESTful Web Services with ASP.NET Core 3

Hands-On RESTful Web Services with ASP.NET Core 3

Samuele Resca
Microservices in .NET Core

Microservices in .NET Core

Christian Horsdal Gammelgaard

Publisher Resources

ISBN: 9781788291576Supplemental Content