Tags

,

What is HTTP?

HTTP is a communication protocol that uses a Request-Response model, that involves a client and a server.

Request

  • This protocol has the following requests format:
<method> <URL> HTTP/<version>

<Headers - Always multiple, one in each row>

<request body>

  • Example:
GET /store/clients HTTP/1.1
Host: localhost:8080
Accept: text/html

Response

  • The response to the requests has the following general format:
HTTP/<version> <status code> <code description>

<Headers>

<response body>

  • Example:
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>

HTTP Methods

  • 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:
  • GET
  • POST
  • PUT
  • DELETE
  • OPTIONS
  • HEAD
  • TRACE
  • CONNECT
Method Idempotent Safe
GET X X
POST
PUT X
DELETE X
HEAD X X
OPTIONS X X
  • 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.

Status Codes

  • 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
  • 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.

Advertisements