Hypertext Transfer Protocol (HTTP) is a TCP/IP-based application layer protocol used for communication and data transfer. HTTP is a request-response protocol with a client-server architecture. The client and server communicate by exchanging individual messages., clients initiate the exchange with an HTTP request, for example, GET, PUT DELETE, and POST, to name the most common.
HTTP is primarily utilized between web browsers and web servers. The web browser acts as the client and requests a web page’s content hosted on a server. When you type a URL into the web browser’s address field, the browser sends an HTTP request to the corresponding server, requesting web content. The server, in turn, processes the client’s requests and either provides the requested content in the form of an HTTP response or returns an error.
HTTP is considered a connectionless and stateless protocol. Being connectionless refers to the fact that a connection’s lifecycle starts with the request and ends with the response, and no connection is preserved after the response from the server. This is advantageous as it prevents the hold-up of resources in idle times.
HTTP is considered a stateless protocol as each data exchange is independent from previous exchanges between the client and the server, which means the server does not keep a history of a client’s previous requests. This is in contrast with the File Transfer Protocol (FTP) for example, where the two entities may keep track of exchanged authentication credentials or the current working directory, for continuity and ease-of-access purposes. This can be an advantage for server implementations as it reduces complexity and eliminates the need for complex overhead data.
HTTP communication is based on a request-response cycle, where the client sends an HTTP request message, containing information such as the request type and additional metadata, and the server responds with an HTTP response.
All HTTP messages are comprised of the following 3 main sections:
The start-line of HTTP requests contains three things: the request method, the request target, and the HTTP version.
The request method refers to the type of request the client wants to initiate. Some of the most common ones are:
2. Request target
The Uniform Resource Identifier (URI) specifies the resource upon which one of the above methods is applied. A URI can be either a Uniform Resource Locator (URL) or a Uniform Resource Name (URN). However, URLs are more commonly used. An example of a URL is https://academy.nordicsemi.com/
3. HTTP version
This indicates the HTTP version being used in the request and is necessary to identify the structure of the rest of the message. And indicates which version to use for the HTTP response.
When an HTTP client, such as a web browser or a user using an HTTP API, sends an HTTP request to an HTTP server, the server responds with a status code explaining its response to that request. The three main response codes we will focus on in this lesson are: