Before learning Rest / Soap / GraphQL, You Need to Understand HTTP !
By: Mecheri Akram
Tags: Rest, Soap, Http Protocol, Rfc2616, GraphQL

HTTP REQUEST / HTTP RESPONSE

The HTTP protocol is a request/response protocol based on the client/server based architecture where web browsers, robots and search engines, etc. act like HTTP clients, and the Web server acts as a server.

1. HTTP REQUEST 💻 ➡ 🌎

Example of an HTTP Request

1–1 Request-Line

An HTTP request must at least have a Request-Line:

$METHOD /$PATH $HTTP_VERSION

E.g:

GET /posts/post-1.html HTTP/1.1

1-1-1 Request-Methods:

Most used HTTP Methods :

GET : this method means retrieve whatever information (in the form of an

entity) is identified by the Request-URI.

: this method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. POST : the actual function performed by the POST method is determined by the server, in most cases it’s used to post a message as a new subordinate of the resource identified by the Request-URI.

: the actual function performed by the POST method is determined by the server, in most cases it’s used to post a message as a new subordinate of the resource identified by the Request-URI. PUT : this method requests that the enclosed entity be stored under the

supplied Request-URI. If the Request-URI refers to an already

existing resource, the enclosed entity SHOULD be considered as a

modified version of the one residing on the origin server. If the

Request-URI does not point to an existing resource, and that URI is

capable of being defined as a new resource.

: this method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource. DELETE : this method requests that the origin server delete the resource

identified by the Request-URI.

this method requests that the origin server delete the resource identified by the Request-URI. OPTIONS : this method represents a request for information about the

communication options available on the request/response chain

identified by the Request-URI, such as pre-flight requests for Cross Origin Ressource Sharing (CORS).

Other HTTP Methods exists like : HEAD, CONNECT, PATCH… we will not cover them in this article because they are rarely used in API design.

1–1–2: Request-URI (Path):

The Request-URI is a Uniform Resource Identifier and identifies the resource on the server upon which to apply the request.

1-2 Request-Headers:

The Request-header fields allow the client to pass additional information about the request, and about the client itself, to the server. these information are exploited by the server in different ways such as Authentication, Routing, Analytics and so on.

E.g:

User-Agent: Used to identify the HTTP client.

Authorization: Used for authentication purpose.

Host: Identifies the server being requested.

Content-Type: Identifies the MIME type of the entity-body carried in

HTTP Request or Response.

1–3 Request-Body:

The Request-Body of an HTTP Request is used to carry the entity-body associated with the request, A Request-Body MUST NOT be included in a request if the specification of the request method does not allow sending an entity-body in requests.