Introducing REST APIs Chapter 4
HTTP verbs
HTTP verbs are the different methods that are used to define the action that we want to
execute for the resources. The most used HTTP verbs are GET, POST, PUT, PATCH, and
DELETE. HTTP verbs are the request methods that make it possible to communicate
between multiple applications. These HTTP verbs make it possible to perform several
actions on a resource without needing to alter the URLs entirely. Let's look into each of
these in more detail.
GET
GET requests are the idempotent requests. This is used when we want to fetch the
information about resources. This does not modify or delete the resource. The equivalent
CRUD operation for GET requests is READ, which means it only fetches the information and
that's it. An example URL for a GET request is:
To fetch all records:
GET http://www.example.com/users
To fetch information about a single user:
GET http://www.example.com/users/{user_id}
POST
The equivalent CRUD operation for the POST request is CREATE. This is used with new
records to the collection. Since this changes the state of the server, this is not an idempotent
request. If we request a POST method twice with the same parameters, that will create two
new identical resources in the database. An example URL for a POST request is:
POST http://www.example.com/users/