Introduction to http

Introduction to http

Http or hyper text transfer protocol is transfer protocol on which the whole web relies on, http makes it possible for us to load web pages and that's the reason it is essential to learn about it.

Hypertext Transfer Protocol (HTTP) is an application-layer protocol used to send documents like HTML. It makes communication between web browsers and web servers possible.

A typical http flow works like : a client makes a request to a server , and the server sends a response message to client, which basically means requests are initiated by the recipient(client), usually the browser. complete document(dom) is reconstructed from the different sub-documents fetched, like text, layout of the web page , images, videos(static resources),scripts etc.

lets understand more on http request and its components.

What is in a HTTP request?

An HTTP request is the way the client asks the information from a web server. When you enter a URL in your browser's address bar, click on a link, or submit a form on a webpage, your browser generates an HTTP request to the server hosting the website.

A HTTP request made carries with it a series of encoded data that carries different types of information like the method, request headers,Optional HTTP body,HTTP version.

lets deep dive into how these requests work, and what role the information in the request play!

HTTP methods

An HTTP method is like a set of instructions telling the server what to do when you ask for something. Think of them as action words, or sometimes people call them HTTP verbs. The two main ones are GET and POST:

- The GET method requests for a data representation of the asked resource. Requests using GET can retrieve data.

- The [POST](localhost:5173/blog/(https:/developer.mozil.. method sends data to a server so it may change its state. This is the method often used in html forms to send information or data to server.

HTTP request headers

Request headers contain text information stored in key-value pairs, and they are included in every HTTP request (and response, more on that later). These headers communicate core information, such as what browser the client is using and what data is being requested.

here is how it looks :

http-header-img

What is in an HTTP request body?

The body of an HTTP request is the section that carries the actual data being sent to the server. It includes information like usernames, passwords, or any other data entered into a form on a website. This data is crucial for the server to process and respond accordingly.

For example, when you submit a form on a webpage, the details you enter, such as your name and email address, are included in the body of the HTTP request that gets sent to the server for processing. This separation of headers (containing metadata) and the body (containing actual data) allows for efficient communication between the client and the server on the web.

what is a an HTTP response?

An HTTP response is what clients receive from the server in return of an HTTP request.These responses provides the information around what the client asked for . Now the http response also contains 3 informations or has 3 parts :

  1. status code

  2. response headers

  3. Body

let me break it down further one by one :

HTTP status code : status codes are three-digit codes that provide context about the result of an HTTP request made by a client to a server and there are 5 categories of it like

  1. 1xx Informational

  2. 2xx Success

  3. 3xx Redirection

  4. 4xx Client Error

  5. 5xx Server Error

and "xx" can be anything from 0-99.

  • 2xx (Success): Starting with '2' indicates a successful request. For instance, '200 OK' signifies that the client's request for a webpage was properly completed.

  • 4xx (Client Error): Starting with '4' means there was an error on the client side. A common example is '404 NOT FOUND,' which occurs when there's a mistake in the URL, like a typo.

  • 5xx (Server Error): Starting with '5' indicates an error on the server side. For example, '500 Internal Server Error' suggests that something went wrong within the server while processing the request.

  • 1xx (Informational): Starting with '1' denotes an informational response. However, these codes are not as commonly encountered during regular web browsing.

  • 3xx (Redirection): Starting with '3' signifies a redirection. These codes instruct the client to take further action to complete the request.

HTTP Response Headers :

response headers provide additional context on the response and the data being sent in the response body. and it looks something like this :

HTTP response headers

(got this img from google , because am too lazy to inspect and make a screenshot )

HTTP response body:

When you ask a website for something using your browser, like opening a webpage, the server usually sends back a response. If everything goes well (like a '200 OK' status), the server puts the requested info in the response body. For most web stuff, that info is in the form of HTML, the language browsers use to create webpages. So, your browser takes that HTML and turns it into the webpage you see!

see you in next blog!