HTTP is just a communication protocol over TCP. In other words, just one of the ways in which clients communicate with servers via some specially organized string.
Some fancy alien technology which requires vast knowledge of quantum physics :D. Anyone can easily implement the HTTP protocol either as a client or as a server side.
For HTTP to be valid and acceptable for any client/server it should have the following:
REQUEST/STATUS LINE\r\n
HEADER1\r\n
HEADER2\r\n
...\r\n
HEADERX\r\n
\r\n
OPTIONAL REQUEST/RESPONSE
HTTP VERB / METHOD ␣ URL/URI ␣ HTTP VERSION
GET /some/uri HTTP/1.1
HTTP VERSION ␣ STATUS CODE ␣ REASON PHRASE
HTTP/1.1 200 OK
Note: Also in order for the HTTP request/response to be valid it also need to
have Content-Length header provided. In the request it equals to the length of the request
body, and should be present only if request body is present. In case of response should be equal
to the length of the response body if any.
Generally speaking HTTP Verbs or Methods are ways to describe how
the client is going to have an effect on some resource located on the server,
like GET or POST for example.
Because HTTP is just a communication protocol, nobody restricts you to use specific methods aka verbs. However, there are different verbs for different kinds of actions on resources on the server.
Here are the most widely used and known verbs:
GET- typically used for getting resourcesPOST- typically used for creating a resource or executing an action with side effectsPATCH- typically used for partially updating resourcesPUT- typically used for fully updating resourcesDELETE- typically used for deleting resources
However, there are other verbs/methods, such as:
OPTIONS, CONNECT, TRACE, HEAD
which we will not care to use, or rarely do so.
HTTP Statuses are used for the server to communicate the client the result of its request,
meaning if the client made a request, it can generally know how the server responded and what's
the result of his action by simply getting back a Status Code in the response.
Status Codes usually come hand in hand with Reason Phrases. So a Status Code is made up of:
NUMBER ␣ REASON PHRASE, something like:
200 OK400 Bad Request
There are many status codes, and you can even create your own Custom Status Codes, however generally
speaking you should know:
1.X.X- Represents Informational statuses2.X.X- Represents Success statuses3.X.X- Represents Redirects statuses4.X.X- Represents Client Error statuses5.X.X- Represents Server Error statuses
HTTP 1 - Good old HTTPHTTP 2 - SPDYHTTP 3 - QUIC
connectionisclosedafter every request/response (results in inefficiency)
- requires
Hostheader - allows
persistent connections(multiple request/response on the same connection) - introduces the
OPTIONSmethod mainly used for CORS - has improved caching mechanism
- introduces
100status code which lets the client know whether to proceed sending a large request body - introduces chuncked transfer encoding
- introduces
Connectionheader - introduces enhanced compression support
- Much more (Generally stick with HTTP/1.1)
Generally speaking REST is nothing, but a community effort & instruction around HTTP on how to properly structure URLs and use HTTP Verbs & Statuses. So REST is the same old HTTP used properly, with a little less freedom and at the end of the day it's a lot of debate on how to properly use it, hence it's just a recommendation which most companies follow.
Web SocketsHTTP2/HTTP3gRPCGraphQL