HyperText Transfer Protocol (HTTP) uses a client-request/server-response model. The protocol is stateless, which means it does not require the server to retain information or status about each user for the duration of multiple requests. However, for performance reasons and to avoid the connection-latency issues of TCP, techniques like persistent, parallel or pipelined connections may be used.
The request is sent with an HTTP method:
HEAD- used to retrieve the
GETresponse header without the actual content (i.e., just the metadata in the content).
GET- used to retrieve data, where the request body is ignored.
POST- used to send data, contained in the request body, to the server.
These are all the methods supported by older browsers, but the HTTP 1.1 specification includes a few more:
The response is returned with a status code:
2xxindicates success, most pages will have a
3xxare used for redirections
4xxcodes are used for errors with the request, the commonest being
404for "Page not found"
5xxare used for server errors
Both the request and response are made up of a header and an optional body.
The header contains a list of key-value pairs, separated using new lines and colons. For example, a request may have headers like this:
Proxy-Connection: keep-alive Referer: URL User-Agent: browser name or client application Accept-Encoding: gzip,deflate Accept-Language: en-GB
Note that in the example the request is telling the server that the response can be sent with the body compressed with either gzip or DEFLATE encoding.
The request needs a body if it is sending additional data to the server, for instance, if sending information entered into a form.
The response headers will include information telling the client how to deal with the response data, for instance, whether they can cache the data (and how long for).
The response body 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 instance, as a soap, rest, or graphql service.
- HTTP/0.9 - 1991 / 1992
- HTTP/1.0 - RFC1945 - May 1996
- HTTP/1.1 - RFC2068 - January 1997 / RFC2616 - June 1999
- RFC 7230, HTTP/1.1: Message Syntax and Routing - June 2014
- HTTP/2.0 - RFC7540 - May 2015
- HTTP Methods: GET vs. POST
- HTTP in the Mozilla Developer Network
- Hypertext Transfer Protocol -- HTTP/1.1 Standards (RTC 2616)