The Anatomy of HTTP Requests

Rapid
The Anatomy of HTTP Requests
The Anatomy of HTTP Requests

The Anatomy of HTTP Requests.

Rapid
The Anatomy of HTTP Requests
The Anatomy of HTTP Requests

HTTP Requests typically contain three things: a request line, header fields, and a body(This one is optional).

Rapid
The Anatomy of HTTP Requests
The Anatomy of HTTP Requests

The request line is composed of three parts. Firstly, the HTTP Method, such as GET, POST, or DELETE. Secondly, the resource URL. This locates the requested resource on the server. Thirdly, the current HTTP version. The request line is like the foundation of a request, like a pizza base.

Rapid
The Anatomy of HTTP Requests
The Anatomy of HTTP Requests

The second layer to our pizza is HTTP Header fields. These provide extra information to the server about the request. There are many different headers—for example, Content-type, which indicates the data format. Content-length indicates the length of the data in bytes. Accept-Language indicates the language of the content accepted by the client.

Rapid
The Anatomy of HTTP Requests
The Anatomy of HTTP Requests

The last part of the request is the body(data). This part is usually only needed if the HTTP Method is POST, PUT, or PATCH because it contains the new data being sent to the server. For example, in a POST request, the body could contain the details of a pizza order form.

Rapid
The Anatomy of HTTP Requests
The Anatomy of HTTP Requests

Let's review the structure of an HTTP request in full. First, there's a request line that contains the HTTP Method, resource URL, and current HTTP version. Secondly, the HTTP Header fields provide extra information about the request. If the request is GET, this is all the information needed. However, if the request is POST, PUT, or PATCH, there is a body containing a message. An empty line always separates the Headers and the body.

Rapid
The Anatomy of HTTP Requests
The Anatomy of HTTP Requests

That's the anatomy of an HTTP Request! It is now ready to be sent to the server.