Hypertext Transfer Protocol (HTTP) is an application level network protocol that is used for the transfer of content on the World Wide Web.
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 theGET
response 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: PUT
, DELETE
, TRACE
, OPTIONS
, CONNECT
and PATCH
.
The response is returned with a status code:
1xx
are informational2xx
indicates success, most pages will have a200
status3xx
are used for redirections4xx
codes are used for errors with the request, the commonest being404
for "Page not found"5xx
are 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.
Versions
- 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
Resources
- HTTP Methods: GET vs. POST
- HTTP in the Mozilla Developer Network
- Hypertext Transfer Protocol -- HTTP/1.1 Standards (RTC 2616)