HTTP stands for Hypertext Transfer Protocol. It is an application layer protocol used across the world wide web and beyond, it 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.

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 whilst 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

  1. 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. There will just be a header, no request body.

    HTTP/1.1 HEADER
    Request URL: https://example.com/page.html
    Request Method: GET
    Host: example.com
    
  2. The server returns a response. If it could complete the request, this will have a code of 200 (which means ok) and include the contents of the desired resource (page.html) 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>
    
  3. The web browser then uses the data in the body to render the page.

  4. 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.

GET

Request a resource from a server. GET requests should not change or delete any resources on the server.

POST

HTTP POST requests are used to create new data on the server – often adding an entry to a database.

PUT

Update or create a resource.

DELETE

Delete a resource from a server.

HTTP Status Codes

A response includes a status code to indicate the result of the request. HTTP status codes are 3 digits and are broken into different categories, indicated by the first digit. A full list of status codes for HTTP/1.1 is given in RFC 2616 section 10.

1xx – Informational

  • 100 Continue

2xx – Successful

  • 200 OK

  • 201 Created

3xx - Redirection

  • 301 Moved Permanently

  • 302 Found (non permanent redirect)

4xx – Client Error

  • 400 Bad Request

  • 401 Unauthorized

  • 403 Forbidden

  • 404 Not Found

  • 418 I’m a teapot

5xx – Server Error

  • 500 Internal Server Error

  • 503 Service Unavailable