Method in REST API

In a REST API, a method (or HTTP verb) is the action that the client wants to perform on a resource.

The most common methods used in REST APIs are:

  • GET: Retrieves information about a resource.
  • POST: Creates a new resource.
  • PUT: Replaces an existing resource or creates a new one if it does not exist.
  • PATCH: Updates an existing resource.
  • DELETE: Deletes a resource.

These methods correspond to the standard HTTP verbs and are used to indicate the desired action to be performed on the resource.

For example, if a client wants to retrieve a list of products, they would use the GET method and make a request to the “products” resource endpoint. If they wanted to create a new product, they would use the POST method and send a request to the same endpoint with the product information in the request body.

It’s important to note that not all REST APIs will implement all the methods mentioned above, and some may implement additional methods such as a COPY or a MOVE method.

Additionally, REST APIs may have a specific set of rules and constraints for each method, such as requiring authentication for certain methods or limiting the rate of requests for certain endpoints.