HTTP Requests – What Are They?

HTTP – HyperText Transfer Protocol was developed specifically for data transfer and web browsing. Each HTTP interaction looks like a communication between the user and the server: a person using the client makes a request (HTTP Requests) to the server, and the server gives an answer – for example, displays the site in the browser.

In fact, requests are some informational messages that the client sends to the server in order to perform some action. Each HTTP Request must have a URL and method, and the header (HTTP header) is the basis.

HTTP requests are filled with multiple text strings that are encoded in ASCII. Versions of HTTP/1.1 and earlier assumed the use of plain text data. In a more advanced version of HTTP / 2, textual information began to be divided into frames.

Structure of HTTP Requests

HTTP requests might look like this: GET HTTP/1.1

Here you can see that GET is used as the method, the access goes to the resource, and the HTTP/1.1 version is used as the protocol.

To make it clearer, let’s put it like this:

HTTP Requests - What Are They

Traditionally, queries have the following structure:

  1. Start line. Needed to describe a request or status. It reports the protocol version and other information. This can be the requested resource or a response code (for example, errors). The length is exactly one line.
  2. HTTP header. It looks like several lines of text that specify the request or describe the content of the message body.
  3. Empty line. It is needed to report the successful submission of the metadata for a particular request.
  4. Request body. It stores information about the request or the document that is sent in response to the request.

And now a little more detail.

Start line

The start line of an HTTP request includes three main components, the request method, its target, and the version of the data transfer protocol.

Method is a short word that specifies what to do with the requested resource. The most common methods are verbal (GET, PUT, or POST) or noun (HEAD, OPTIONS). GET, for example, lets the server know that the user needs some data, while POST means that the user sends data to the server.

The target of the request is actually a pointer to the URL the user wants. Consists of protocol, URL or IP address, path to a resource stored on the server. Also, the purpose of the request may include an indication of the port, request parameters.

The version of the communication protocol used. HTTP/1.1 and HTTP/2 versions are now common. The structure of the data following the start line depends on the protocol.

Note that other useful information can be stored in the start line. For example, User-Agent header – data about the user agent used, that is, the browser. Or Referer header – this refers to the URL from which the request came.

HTTP header

Headers look like a _name:value_ pair. The string is case insensitive, and the structure of the value is determined by the header. The header looks like one, sometimes extremely long line. Headers are used to send along with a request for more information and can belong to one of four categories.

Main headers are required for any types of messages and do not depend on the data that is planned to be transmitted.

Request headers – specify the parameters of the requested data or define parameters with information about the client making the request.

Response headers – they contain information about the server response.

Entity headers – allow you to describe the content of the message body.

Empty line

In fact, this line is not empty, it contains the CTRLF parameter, which marks the end of the header.

Request Body

Not all requests may have an HTTP request body. For example, for the GET, HEAD, DELETE, OPTIONS methods, the body is usually not needed. But for methods of the POST type, it is necessary – to send information to the server for updating, for example.

The request body is conventionally divided into two categories, single-resource and multi-resource. The first category includes request bodies, which consist of a single separate file with two headers: Content-Type and Content-Length.

Multi-resource bodies consist of several parts, each of which contains its own bit of information. These parts are related to HTML forms.

In addition to HTTP requests, there are also responses. But that’s a completely different story.

Navid Anjum

Full-stack web developer and founder of Laravelaura. He makes his tutorials as simple as humanly possible and focuses on getting the students to the point where they can build projects independently.

Leave a Reply

Your email address will not be published. Required fields are marked *