What is HTTP?
HTTP is a communication protocol that uses a Request-Response model, that involves a client and a server.
- This protocol has the following requests format:
<method> <URL> HTTP/<version> <Headers - Always multiple, one in each row> <request body>
GET /store/clients HTTP/1.1 Host: localhost:8080 Accept: text/html
- The response to the requests has the following general format:
HTTP/<version> <status code> <code description> <Headers> <response body>
HTTP/1.1 200 OK Content-Type: text/xml Content-Length: 245 <clients> <client id="1"> <name>Ronaldo</name> <birthDate>1976-09-18</birthDate> </client> <client id="2"> <name>Neymar</name> <birthDate>1992-02-05</birthDate> </client> </clients>
- Also known as HTTP Verbs. The HTTP 1.1 version formally defines eight methods – though the protocol is extendable in relation to these methods. These eight are:
- The idempotency of a method is the effect that the same request has on server side – the same request, performed multiple times, it causes changes on the server side as if it were a single, then this is considered idempotent.
- The methods are considered safe if they don’t cause any changes in the contained data.
- Every request that is sent to the server returns a status code. These codes are divided into five families: 1xx, 2xx, 3xx, 4xx and 5xx, where:
- 1xx – Informational
- 2xx – Successful Codes
- 3xx – Redirection Codes
- 4xx – Client Errors
- 5xx – Server Errors
- Here is a list of status codes and their definitions: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
- IMPORTANT: The most widely used version of HTTP is still 1.1, but the current version is 2.
In the next post will be informed about more things used in the HTTP, most used Status Codes, headers, etc.
References: SAUDATE, Alexandre. REST – Construa API’s inteligentes de maneira simples. ed. Casa do Código. BR.