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

DELETE

Ideally, a DELETE request should delete the resource. Once the operation is successful, we can send a 200 OK status code by calling the OK() method.

Refer to the following code block:

// DELETE: api/Products/1[HttpDelete("{id}")]public async Task<IActionResult> Delete(int id)  => (await _productService.DeleteOrderAsync(id))    ? (IActionResult)Ok()    : NoContent();

Notice the DeleteOrderAsync method, which is provided with the ID of the product to delete. Now, you can return a Boolean from that method, which will indicate whether the operation was successful or not. If you don't find any product for that ID, simply return false. Then, we will decide what to return to the client accordingly.

If you return false, NoContent() can be used to ...

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