HTTP Requests

HTTP Requests

  • An HTTP request is made by a client, to a named host, which is located on a server

  • The aim of the request is to access a resource on the server.

  • To make the request, the Client uses components of a URL (Uniform Resource Locator), which includes the information needed to access the resource

  • A correctly composed HTTP request contains the following elements:

    • A request line

    • A series of HTTP headers, or header fields

    • A message body, if needed


Request Line

  • The request line is the first line in the request message. It consists of at least three items:
  1. A HTTP method

    • The method is a one-word command that tells the server what it should do with the resource. For example, the server could be asked to send the resource to the client.
  2. The path component of the URL for the request:

    • The path identifies the resource on the server.
  3. The HTTP version number:

    • The HTTP specification to which the client has tried to make the message comply (current version is 1.1 but you don’t have to worry about this)

Example Request Line

GET /path/to/resource/index.html HTTP/1.1

  • the method is GET

  • the path is /path/to/resource/index.html

  • the HTTP version is HTTP/1.1

The HTTP Client (e.g. web browser) is responsible for constructing this request line; as developers we just need to know how this works