An Introduction to HTTP: How It Works

An Introduction to HTTP: How It Works

Hypertext Transfer Protocol

Table of contents

As I’ve already told you about the Internet in my previous article that we use Internet to share our media with others. But how does this actually happen ? How does our request of posting a photo on social media takes place or being more precise how does our request travels across the internet ? 🌐

In order to understand HTTP, you must first understand about the very basic Client-Server model. The person who requests something over the internet is termed as Client and the person who is serving his request is termed as Server. Isn’t it simple ?

  • Client - a client is a program or device that requests a service or resource from another program, called a server.

  • Server - a server is also a program or device that serves the incoming requests from the user.

Now that you have understood what client-server architecture is, let us see what actually happens when you type something on search bar on your browser.

Let’s suppose you searched for chaicode.com. In the search bar above you could see something like this.

https://www.chaicode.com/ . This is known as URL(Uniform resource locator) or it also known as web address. Here you can see something like https/http.

HTTP stands for Hypertext Transfer Protocol. It is the foundation of how data is shared on the Internet. Imagine HTTP as a waiter which takes your order to the chef which then prepares the food and return it back to you. HTTP can transfer various types of data including text(HTML, CSS and JAVASCRIPT) , audio, images, video etc. Messages are composed of plain text, making them relatively easy to read and understand.

HTTPS stands for Hypertext transfer protocol secure. It adds a layer of security in our requests so that no crucial data like username, passwords, credit card details gets hacked by any anonymous user. It encrypts our data before sending it to the server.

Key characteristics :

  • Stateless - Each request is independent of the previous request. Anytime you request something you are a new user.

HTTP headers

HTTP headers are like some extra information/metadata which accompany every HTTP request and response, providing essential context for both the client and server. There are two types of HTTP headers :

  1. Request headers includes :

    • User-Agent - Identifies the client or the browser making request**.**

    • Accept - Specifies the type of content client will accept.

    • Authorization - Contains credentials for authentication (e.g., usernames, passwords, tokens).

    • Cookie - Sends cookies from the client to the server**.**

    • Method - Type of request being sent by the client (GET, POST, PUT, DELETE, PATCH etc)

Response Headers include :

  • Content-Type: Specifies the type of content being returned (e.g., HTML, JSON, image/jpeg).

  • Content-Length: Indicates the size of the response body in bytes.

  • Set-Cookie: Sends cookies from the server to the client.

  • Location: Redirects the client to a different URL.

  • Server: Identifies the web server software being used.


HTTP Methods

HTTP methods specifies the action you want to perform on a particular URL. It tells the server what the client wants to do.

  1. GET

    • Purpose - As the name suggests, it fetches the data from the server.

    • Example - Fetching a webpage, downloading a file etc.

    • Characteristics :

      • Safe - Does not modify data on the server.

      • Idempotent - Repeated requests have the same effect as a single request.

  2. POST

    • Purpose - As the name suggests, it sends data to the server.

    • Example - Submitting a form, uploading a file, creating a new user account etc.

    • Characteristics :

      • Not safe - Modifies data on the server.

      • Idempotent - Repeated requests have different effects.

  3. DELETE

    • Purpose - As the name suggests, it deletes the data from the server.

    • Example -Deleting a file, removing a user account etc.

    • Characteristics :

      • Not safe - Modifies data on the server.

      • Idempotent - Repeated requests have different effects.

  4. PUT

    • Purpose - It updates the data on the server.

    • Example -Updating user info, updating existing file with new one etc.

    • Characteristics :

      • Not safe - Modifies data on the server.

      • Idempotent - Repeated requests have the same effect as a single request.

  5. PATCH

    • Purpose - It partially updates the data on the server.

    • Example -Updating a specific field on user info etc.

    • Characteristics :

      • Not safe - Modifies data on the server.

      • Idempotent - Repeated requests have different effects.

And there are several other less commonly used HTTP methods like HEAD, OPTIONS, TRACE, CONNECT.