What is "http"

HTTP uses a client-request/server-Response model. HTTP is a stateless protocol, which means it does not require the server to retain status information about each user for the duration of multiple requests.

The request is sent with an HTTP method:

  • GET - used to retrieve data, the body of the request should be ignored.
  • POST - used to send data to the server, the body should keep the data

These are all methods supported by older browsers, but the HTTP 1.1 specification includes a little more: HEAD, PUT, DELETE, TRACE, OPTIONS, CONNECT and PATCH.

The answer is returned with a status code:

  • 1xx are informative
  • 2xx indicates success, most pages will have a 200 status
  • 3xx are used for redirects
  • 4xx codes are used for errors with the request, the most common being 404 for a page not found
  • 5xx are used for server errors

Both the request and response consist of a header and an optional body.

The header contains a list of key-value pairs, separated using new lines and two points, for example, a request may have such headers:

    Proxy-Connection: Keep-Alive     Referer: url     User-Agent: browser name or client application     Accept-Encoding: gzip, deflate     Accept-Language: en-EN

Note that in the example, the request is told the server that the reply can be sent with the compressed body with gzip or empty encoding.

The request needs a body if it is sending additional data to the server, for example if the sending of information has entered a form.

Response headers will include information telling the client how to handle the response data, for example whether they can cache the data (and for how long).

The body of the answer will have the requested data, such as the HTML of a web page or image data.

HTTP is used by browsers to retrieve web content, but can also be used for data Apis. For example, such as SOAP or service REST.