Modupe Falodun
The Tinted Hair Dev

Follow

The Tinted Hair Dev

Follow

Common HTTP Request Methods

Modupe Falodun's photo
Modupe Falodun
·Sep 6, 2021·
Common HTTP Request Methods

The Hypertext Transfer Protocol (HTTP) is a set of rules for the transfer of information over the web. HTTP enables communication between clients applications and servers. It indicates the action that a given resource should take upon receiving a request.

HTTP Methods

The five common HTTP methods are POST, GET, PUT, PATCH, and DELETE. These correspond to create, read, update, and delete (or CRUD) operations.

POST

A POST request sends data to a server to create a resource. A post request usually returns a 201(created) status code or a 200(ok) status code. The server returns a 201(created) status code on the creation of a resource. An example of this scenario is when a user is registering on a website. The user inputs their details on a form and clicks the submit button. The user makes a post request to the server with the click of the submit button. The server returns a 200(ok) status code when a request has succeeded. An example is when a user signs in to a website.

GET

A GET request retrieves data from a web server by specifying parameters in the URL part of the request. A GET request retrieves data only and does not change a resource. If the GET request is successful, it returns a 200(ok) status code along with the response body. If the resource is not found then it returns a 404(Not Found) status code. A user fetching all the items in their cart is an example of where we utilise this method. The endpoint would look something like this: GET/items.

PUT

A PUT request updates a resource. PUT requests are idempotent as opposed to POST requests. This means that calling the same resource many times gives the same result. A user updating several details of their profile on a website is an example of where we utilise this method. The endpoint would look like this: PUT/profile/:id. Where the id is the unique identifier of the user.

PATCH

A PATCH request makes a partial update or modification to an existing resource. A user modifying only their profile picture is an example of a PATCH request. The endpoint would look like this: PATCH/profile/:id.

DELETE

A DELETE request deletes the specified resource. A successful response of DELETE requests SHOULD be an HTTP response code of 200(ok). Calling DELETE on the same resource a second time will return a 404( Not found). Deleting an order from a user's cart is an example of a DELETE request. The endpoint would look like this: DELETE/order/:id.

Did you find this article valuable?

Support Modupe Falodun by becoming a sponsor. Any amount is appreciated!

Learn more about Hashnode Sponsors
 
Share this