HTTP Verbs in ASP.NET Web API

The HTTP (Hypertext Transfer Protocol) is the foundation of the World Wide Web. It is an application protocol that allows communication between different systems on the internet. One of the key features of HTTP is the use of verbs (also known as methods or actions) to perform specific operations on resources. In the context of ASP.NET Web API, these HTTP verbs are used to create, read, update, and delete data. 

The following are the five most commonly used HTTP verbs in the ASP.NET Web API:

  • Get
  • Post
  • Put
  • Delete
  • Patch

Let's learn about each http verb in brief.

GET :

This verb is used to retrieve data from the server. It is a read-only operation that does not change any data on the server. A GET request is used to retrieve a representation of a resource from the server.

Example: 

The following endpoint retrieves a list of all employees.

GET /api/Employee/ListEmployees

POST 

This verb is used to create new data on the server. It is a write operation that adds a new resource to the server. A POST request is used to submit an entity to the specified resource, often causing a change in state on the server.

Example:

The following endpoint create or add the employee.

 POST /api/Employee/CreateEmployee .

PUT 

This verb is used to update existing data on the server. It is a write operation that replaces an existing resource with a new one. A PUT request is used to update a resource with the client-provided data.

Example: 

The following endpoint updates employee with ID 1.

PUT /api/Employee/updateEmployee/1 .

DELETE

This verb is used to delete data on the server. It is a write operation that removes a resource from the server. A DELETE request is used to delete a resource identified by a URI.

Example:

The following endpoint deletes employee with ID 1.

 DELETE /api/Employee/deleteEmloyee/1.

PATCH 

This verb is used to update partial data on the server. It is a write operation that modifies a portion of an existing resource. A PATCH request is used to update a resource with only the specific changes provided in the request body.

Example: 

The following endpoint updates a specific property of employee with ID 1.

PATCH /api/Employee/partialupdate/1 

Refer to the following articles to learn how to use HTTP verbs in the ASP.NET Web API and other scenarios.


Summary

The HTTP verbs in the ASP.NET Web API provide a simple and standard way of performing CRUD (create, read, update, and delete) operations on resources. The choice of verb depends on the type of operation you want to perform on a resource. When used properly, HTTP verbs help ensure that your web API is secure, reliable, and scalable.

Post a Comment

www.CodeNirvana.in

Protected by Copyscape
Copyright © Compilemode