---
title: "How to handle resource updates and deletions using HttpPut and HttpDelete methods in an API."  
description: "How to handle resource updates and deletions using HttpPut and HttpDelete methods in an API."  
author: "Sandra Emily"  
published: 2023-10-29  
updated: 2023-10-30  
canonical: https://www.mindstick.com/forum/160303/how-to-handle-resource-updates-and-deletions-using-httpput-and-httpdelete-methods-in-an-api  
category: ".net core"  
tags: ["http post", ".net core", ".net core api"]  
reading_time: 3 minutes  

---

# How to handle resource updates and deletions using HttpPut and HttpDelete methods in an API.

How to [handle](https://www.mindstick.com/articles/311004/suede-skillet-handle-cover) [resource](https://www.mindstick.com/blog/43433/top-best-resources-for-women-about-beauty-and-health) [updates](https://yourviews.mindstick.com/view/85235/global-efforts-to-combat-climate-change-updates-and-initiatives) and deletions using [HttpPut](https://www.mindstick.com/forum/160302/what-is-the-importance-of-request-headers-in-httpput-and-httpdelete-operations) and HttpDelete [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) in an API.

## Replies

### Reply by Aryan Kumar

Handling resource updates and deletions using HTTP PUT and DELETE methods in an API involves defining the routes, implementing the necessary controller methods, and following RESTful principles. Here's how you can do this in a .NET Core API:

## Resource Update (HTTP PUT):

**Define the Route**:

- In your API's routing configuration (usually in Startup.cs), define a route for updating a specific resource. This route should include a parameter to identify the resource to update (e.g., an ID).

```plaintext
[HttpPut("api/resource/{id}")]
public IActionResult UpdateResource(int id, [FromBody] Resource updatedResource)
{
    // Logic to update the resource with the specified ID.
}
```

**Controller Method**:

- Create a controller method that accepts an HTTP PUT request. The method should include a parameter to receive the resource's unique identifier (e.g., **id**) and a parameter to receive the updated resource data (e.g., **updatedResource**).

**Update Logic**:

- Inside the PUT method, implement the logic to update the resource identified by the **id** parameter with the data provided in the **updatedResource** parameter.

**Response Handling**:

- Return an appropriate HTTP status code, such as 200 OK for a successful update, 204 No Content if no response body is needed, or 404 Not Found if the resource doesn't exist.

## Resource Deletion (HTTP DELETE):

**Define the Route**:

- Define a route for deleting a specific resource. Like with updating, the route should include a parameter to identify the resource to delete (e.g., an ID).

```plaintext
[HttpDelete("api/resource/{id}")]
public IActionResult DeleteResource(int id)
{
    // Logic to delete the resource with the specified ID.
}
```

**Controller Method**:

- Create a controller method that accepts an HTTP DELETE request. The method should include a parameter to receive the resource's unique identifier (e.g., **id**).

**Deletion Logic**:

- Inside the DELETE method, implement the logic to delete the resource identified by the **id** parameter.

**Response Handling**:

- Return an appropriate HTTP status code, such as 204 No Content for a successful deletion, 404 Not Found if the resource doesn't exist, or 403 Forbidden if the client does not have permission to delete the resource.

In both cases, it's essential to follow RESTful principles and use appropriate status codes to provide clear communication about the outcome of the request. Additionally, consider implementing authentication and authorization mechanisms to control who can update or delete resources, and handle errors gracefully by providing informative error responses when needed.


---

Original Source: https://www.mindstick.com/forum/160303/how-to-handle-resource-updates-and-deletions-using-httpput-and-httpdelete-methods-in-an-api

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
