REST API VERBS. Make sure you follow the best REST practices

Facebook
Twitter
LinkedIn

Never miss a post!

Sign up for our newsletter and get FREE Development Trends delivered directly to your inbox.

You can unsubscribe any time. Terms & Conditions.
Categories

A REST API is also known as RESTful API is an API that allows one application to access features of the other application through its functions and procedures. It allows the interaction between a client and web services following REST architecture. It is also considered as a set of guidelines or rules to develop an API.  It uses HTTP protocol to facilitate the processing of data. You can perform the following operations to do the data manipulation:

  • GET – refers to reading data
  • POST – refers to creating data
  • PUT – refers to updating data
  • DELETE – refers to deleting data

REST API VERBS

REST API allows you to perform CRUD operations in an API by using HTTP methods. An API must return a three-digit HTTP response code to the requested client in a proper manner as it indicates the resulting behavior of an API.

HTTP GET

HTTP GET method is used to retrieve information from an API and it should not be used to modify data. These methods do not change the state of a request or resource, thus are also known as safe methods. Ideally, these methods must be idempotent, i.e., single or consecutive requests made by one or multiple clients must not bring any impact on the state of a server.

HTTP GET http://www.yourapiurl.com/students

HTTP GET http://www.yourapiurl.com/students/ABC

 

GET API Response Code

  • HTTP 200 (OK)

If the resource or method is found in an API, then it must return an HTTP response code of 200 (OK). If the data is also present, it must be attached to the response body which can be either in XML or JSON format.

  • HTTP 404 (NOT FOUND)

If the resource is not found in an API, then it must return HTTP response code 404 (Not Found).

  • HTTP 400 (BAD REQUEST)

If the resource is found in an API but unable to produce any result to the programming exception or is not properly formatted, then it must return HTTP response code 400 (Bad Request).

HTTP POST

HTTP POST method is used to create a new resource or information into an application. It is recommended to use the POST method when sending data to the API. These methods are non-cacheable and are not considered as safe or idempotent.

HTTP POST http://www.yourapiurl.com/students

HTTP POST http://www.yourapiurl.com/students/ABC

 

POST API Response Code

  • HTTP 201 (CREATED)

If the resource is succeeded and a new resource is created as a result, then it must return an HTTP response code 201 (Created).

  • HTTP 204 (NO CONTENT) or HTTP 200 (OK)

If the resource is modified, then ideally it should return a complete response with an HTTP response code 204 (No Content) or HTTP 200 (OK).

HTTP PUT

HTTP PUT method is used to modify an existing resource or information in an API. If the resource is not present, it may create a new resource depending on how the API method is written or the requirements are. It does not cache the responses in an API.

HTTP PUT http://www.yourapiurl.com/students

HTTP PUT http://www.yourapiurl.com/students/ABC

 

PUT API Response Code

  • HTTP 201 (CREATED)

If a new resource is created using the PUT method, then it should return an HTTP response code 201 (Created).

  • HTTP 204 (NO CONTENT) or HTTP 200 (OK)

If an existing resource is modified, then ideally it should return a successful response with an HTTP response code 204 (No Content) or HTTP 200 (OK).

HTTP DELETE

HTTP DELETE method is used to delete identified resources. After deleting a resource, it is also removed from the collection of resources.

HTTP DELETE http://www.yourapiurl.com/students

HTTP DELETE http://www.yourapiurl.com/students/ABC

 

DELETE API Response Code

  • HTTP 200 (OK)

If a resource is deleted successfully and it has a response entity, then it must return an HTTP response code 200 (OK).

  • HTTP 204 (NO CONTENT)

If a resource is deleted successfully and it does not have a response entity, then it must return with an HTTP response code 204 (No Content).

HTTP PATCH

HTTP PATCH method is used to modify an existing resource in a partial manner but not the complete resource. It is neither safe nor idempotent.

HTTP PATCH http://www.yourapiurl.com/students

HTTP PATCH http://www.yourapiurl.com/students/ABC

 

PATCH API Response Code

  • HTTP 200 (OK)

If a resource is updated partially and it has a response entity, then it must return an HTTP response code 200 (OK).

  • HTTP 204 (NO CONTENT)

If a resource is updated partially and it does not have a response entity, then it must return with an HTTP response code 204 (No Content).

 

Facebook
Twitter
LinkedIn

Our website uses cookies that help it to function, allow us to analyze how you interact with it, and help us to improve its performance. By using our website you agree by our Terms and Conditions and Privacy Policy.