Sir Tim Berners-Lee developed the first version of the Hypertext Transfer Protocol (HTTP) as early as 1989 as the basis for simple communication over a network. The goal was a fast exchange of messages among the teams at the CERN nuclear research center in Switzerland. To this day, communication and data transfer between a server and a browser on the internet build on this base protocol. Many protocol extensions have been added since then, above all in the area of security, and a more efficient way of establishing connections has become standard.

Structure and Function of the HTTP Protocol

To communicate on the internet, two parties must be able to exchange data with each other. One party requests information from a server, and the provider of the data then responds by sending the corresponding messages. For this to run smoothly, a protocol must define the format and the set of rules used. The HTTP protocol defines two basic functional blocks for this purpose.

  • The HTTP message header is the head section that defines the meta information, such as content types and any encodings
  • The HTTP message body is the message section that ultimately contains the requested information

When a user wants to open a search query (HTTP request) in the browser, the domain name used (for example http://www.google.com) is first translated into the corresponding internet address so that the target server can be reached. The request is then forwarded to this server and evaluated. In the message header, the server finds further important information about the search query (for example https://www.google.com/search?q=Android&ie=utf-8&oe=utf-8&client=firefox-b-ab) in the following form.

  • search?q=Android denotes a search query that is directed at the Google server. The HTTP query parameter q carries the search term Android
  • The subsequent parameters &ie=utf-8 and oe=utf-8, which are always introduced with the ampersand as a separator, declare the character encoding used by the user’s browser (here UTF-8).
  • A further parameter, &client=firefox-b-ab, tells the server which browser application the user is working with (here Mozilla Firefox).

In response to this request, the server can now compile the corresponding data and send it back to the user as a reply (HTTP response).

HTTP Methods

To establish successful communication between the client (user) and the server (recipient), the HTTP protocol uses different methods for data transfer. They allow different actions to be performed and executed directly on the server. The following overview shows the methods available in HTTP 1.1.

MethodDescription
GETRequests a resource (for example an HTML file or an image)
POSTIs used to transfer larger amounts of data
PUTAddresses a specific resource and instructs the server to create or replace it
PATCHApplies partial changes to a resource
DELETEDeletes the resource identified by the URL from the server
HEADRequests the response header from the server
OPTIONSLets the client determine the available HTTP methods and communication parameters
TRACECreates a trace of an HTTP request between client and server
CONNECTIs used to set up a transmission tunnel between client and server

The HTTP Methods GET and POST in Detail

The two most frequently used methods are the following.

MethodDescription
GETThis method requests a resource, such as a web page.
POSTThis method lets you attach further data to the request for processing, which the server then evaluates. The data is usually encoded as value pairs (for example name=Muster and vorname=Manfred).

GET Request

The following example shows a GET request. In terms of content, the server delivers a chart for foreign exchange rates to the client.

GET /devisen/chart HTTP/1.1
Host: www.mydomain.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:61.0) Gecko/20100101
Firefox/61.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

POST Request

When a user signs up for a newsletter on a website, for example, the HTTP method POST is often used. The data from the web form is transferred to the server in the HTTP request and then evaluated.

POST /newsletter HTTP/1.1
Host: www.mydomain.com
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 170
Connection: keep-alive

anrede	Herr
email	mmusterhaus@testdomain.de
mode	register
pass	mamust
user	Manfred Musterhaus

The actual sign-up data is transferred outside the URL. It is appended to the header as value pairs after a separating blank line. The server can then interpret and process the data accordingly. POST can also transfer very large amounts of data.

Status Codes

A server usually answers a request made with the GET or POST method with a response header. Among other things, it contains a status code with a plain-text message that indicates whether the request was successful.

The following example shows a successful case. The status 204 No Content merely informs the client that the server has processed the request successfully and does not deliver a body itself. This approach reduces the traffic between client and server.

HTTP/1.1 204 NO_CONTENT
Location: https://www.mydomain.com
Server: Apache
Connection: Keep-Alive
Content-Length: 0

To cover the large number of status messages, they have been divided into a total of five classes with the following ranges.

Status CodesDescription
100-199Status messages with purely informational content
200-299Represent successful processing by the server
300-399Messages that concern the transfer, such as Moved Temporarily
400-499Error messages for errors that can be traced back to the client, such as Bad Request
500-599Error messages for errors that are triggered by the server, such as Internal Server Error

Conclusion

For communication on the internet, the HTTP protocol provides the corresponding rules, methods, and status codes. This ensures that all parties use a uniform procedure for exchanging information and data. Because HTTP is a "stateless" protocol, however, web applications sometimes rely on additional mechanisms such as sessions. Modern web applications, in contrast, also support stateless HTTP communication.

Share LinkedIn X Email