Member-only story

REST API Best Practices : The Main Elements of an HTTP Request

Pavle Djuric
6 min readDec 12, 2021
Photo by Diane Picchiottino on Unsplash

An HTTP request consists of three main elements:

The request line, the headers and the message body.

In this article I will be examining each of these elements and all of the building blocks that they use. A well designed REST API needs to make proper use of all of these building blocks.

The Request Line

The request line consist of the following elements:

  1. The method describing the action we want the server to perform (GET, POST, PUT, PATCH, DELETE etc.).

When designing your REST API, make sure to use the proper method for each endpoint. It’s relatively easy, since nearly all of your requests will be using one of the five that I have mentioned. GET will be for all queries that need to retrieve data. POST will be for all newly created data. DELETE will be used for deleting data (pretty obvious, right?). As far as PUT/PATCH, the general rule is that you should use PATCH when you are sending only the field(s) being updated, while PUT requests should contain the entire resource, including the fields that are not being updated. The reason for this, is because ideally PUT should try to update an existing resource, however if that resource does not exist, it should create a new one. I personally prefer PATCH…

--

--

Pavle Djuric
Pavle Djuric

Written by Pavle Djuric

Software developer. 3 x AWS certified. Writing mostly about Python, Golang, backend development and Cloud computing.

No responses yet