How does HTTP work?
HTTP stands for Hypertext Transfer Protocol. HTTP is an application layer protocol used across the world wide web, which typically runs on top of TCP. It enables browsers, and other applications, to ask web servers for pages which they can display. It was born as part of the WorldWideWeb project led by Tim Berners Lee and his team at CERN. It was officially introduced as HTTP V1.0 in RFC 1945 in 1996. HTTP has been assigned TCP port 80 by IANA. Today HTTP/1.1 is the most commonly used version.
It is a request-response protocol with a ‘user agent’ acting as a client which communicates with a server. HTTP headers are used to provide information about the request or response while the body of the message contains the content to be rendered by the client or to be processed by the server.
How a browser gets a web page
The web browser will make a GET request to the server and will specify the location of the resource it is requesting and the version of HTTP it wants to use. This request only includes a header - there is no body component.
HTTP/1.1 HEADER Request URL: https://example.com/page.html Request Method: GET Host: example.com
The server returns a response. If it could complete the request, this will have a code of 200 which means the request was successful. The content of the desired resource (page.html) is sent in the body of the response.
HTTP/1.1 Header Response: 200 OK Date: Mon, 01, Jan, 2001 13:00:00 GMT Content Type: text/html HTTP/1.1 BODY <html> <head> <title> Hello World </title> </head> <body> <h1>Hello World</h1> <p> This is a page. </p> </body> </html>
The web browser then uses the data in the body to render the page.
It may be necessary to make further requests to get other objects needed by the page such as CSS style sheets and images which can also be retrieved using HTTP.
Types of HTTP Request
There are various request methods which can be used with HTTP.
Request a resource from a server. GET requests should not change or delete any resources on the server.
HTTP POST requests are used to create new data on the server – often adding an entry to a database.
Update or create a resource.
Delete a resource from a server.
HTTP Status Codes
A response includes a status code to indicate the result of the request. There are different categories of status code, indicated by the first digit. A full list of status codes is given in RFC 7231.
1xx – Informational
- 100 Continue
2xx – Successful
3xx - Redirection
301 Moved Permanently
302 Found (temporary redirect)
4xx – Client Error
400 Bad Request
404 Not Found
418 I’m a teapot
5xx – Server Error
500 Internal Server Error
503 Service Unavailable
Test your knowledge with these questions.
Learn more about this topic by checking out these references.
Learn more by checking out these related lessons
This lesson is part of the following courses.