DEV Community

Hady Eslam
Hady Eslam

Posted on

HTTP introduction

HTTP

Who else not heard of http in the industry or outside it, as it the language that make the clients ( Like Browsers, Aplications, Robots, Crawlers, etc ) and servers communicate with each other. and there is HTTPS Which is an Encrypted and secure version of HTTP So no man in the middle can steal your data When your client communicats with the server. It is like sending messages to each others and thats the concept that http is build upon


HTTP-Messages

HTTP Messages Have Two Types :

  1. Request Messages : These are the messages that your client send to your
  2. Response Messages : These are the messages that the server respond to your client which return the requested resource which the client request

HTTP-Message-Components

HTTP Messages ( Request or Response ) Consists Of Three Parts

  1. Start Line
  2. Headers
  3. Message Body

1. Start Line

It is the start line of the message which determine if this message is request message or response message.

Request Start Line

The start line for request message is like this
[HTTP Method] [Resource Path] [HTTP/major.minor]

  1. HTTP Method is the method that the client use to his Request.
    The Common Methods Used is

    • GET
    • POST
    • DELETE
    • PUT
    • PATCH
    • CONNECT
    • HEAD
    • OPTIONS
    • TRACE
  2. Resource Path is the resource path or the data path which the client wants from the server.

  3. HTTP/major.minor is the HTTP Version which is consist of major version and minor version because there is http versions out there.

    • HTTP/0.9 which is the older version
    • HTTP/1.0
    • HTTP/1.1 which is The Commonly used version
    • HTTP/2.0 I think it is the last version

And Be Careful because there is space between the method and resource path and http version.

An Example For HTTP Request Message

GET /http/What-is-HTTP HTTP/1.1
Host : dev.to
Enter fullscreen mode Exit fullscreen mode

Response Start Line

The Start Line for the response message is like this
[HTTP/major.minor] [Response Code] [Response Description Line]

  1. HTTP/major.minor is The HTTP version
  2. Response Code is the response code that the server respond to client with it like

    • 404 Which mean this resource not found
    • 200 Which mean the resource found and there it is
    • ...etc
  3. Response Description Line this is just description text for the humans to understand. also note that the code for machine and the text for humans

An Example On HTTP Response Message

HTTP/1.1 200 Success
Server : Apache
Content-Type : text/html
Content-Length : 12

Hello World!
Enter fullscreen mode Exit fullscreen mode

2. Headers

Headers is the data that describe the message and also an instructions to the message receiver ( client or server ) and contain other useful info about the message.

An Example on it

Server : Apache
X-Frame-Options : SAMEORIGN
Content-Length : 15
Enter fullscreen mode Exit fullscreen mode

There is Many Headers But They Have Four Types

  1. General Headers Which Used in Request and Response Messages
  2. Entity Headers Which Contains information About The Message
  3. Request Headers Which is Headers That Reside in Request Messages
  4. Response Headers Which is Headers That Reside in Response Messages

3. Message Body

It Is The Resource Or Data The Client Wants Or The Server Receive


For More Resources I Think MDN Is Greet Place

Top comments (0)