A Beginner’s Guide to Hypertext Transfer Protocol (HTTP)

EGA SAICHARANEGA SAICHARAN
4 min read

As a web developer, understanding the fundamentals of how the web works is crucial. At the core of web communication is the Hypertext Transfer Protocol (HTTP). In this blog, we’ll explore the essentials of HTTP, URLs, and how clients and servers communicate over the web.

1. Web Resources

A Web Resource is any type of data that can be accessed on the internet. This could be anything from an HTML page to a video.

Examples of web resources:

  • HTML documents

  • CSS files

  • JSON data or plain text

  • Images, videos, and more

2. Uniform Resource Locator (URL)

A URL is a text string used to specify the location of a web resource on the internet. It’s what we type into the browser to access websites and online content.

URL Syntax:

protocol://domainName/path?query-parameters

Example:

http://www.flipkart.com/watches?type=digital&rating=4
  • http: The Protocol (more on this below)

  • www.flipkart.com: The Domain Name (points to a specific web server)

  • /watches: The Path (indicates the resource on the server)

  • type=digital&rating=4: Query Parameters (criteria for refining the resource)


2.1 Protocol

A protocol is a set of rules that allow electronic devices to communicate. Here are a few common ones:

  • HTTP (Hypertext Transfer Protocol): Used to transfer resources over the web.

  • HTTPS (Hypertext Transfer Protocol Secure): The secure version of HTTP, where data is transferred in encrypted form.

  • WebSockets: Used for real-time, bidirectional communication.

2.1.1 HTTP:

HTTP is the primary protocol used for sending and receiving web resources, like web pages, data from APIs, and multimedia.

  • HTTP Request: Message sent by the client (usually the browser) to request a resource.

  • HTTP Response: Message sent by the server in response to the client’s request.

2.1.2 HTTPS:

HTTPS ensures that communication is secure by encrypting the data being transferred. It’s vital for sites dealing with sensitive information like login pages, payment gateways, and emails.


2.2 Domain Name

The Domain Name specifies which web server is being requested. For example, in the URL www.flipkart.com, the domain name points to Flipkart's web server.

2.3 Path

The Path identifies a specific resource on the server. For example:

  • /watches in http://www.flipkart.com/watches

  • /electronics/laptops/gaming in http://www.flipkart.com/electronics/laptops/gaming

2.4 Query Parameters

Query Parameters add criteria or filters to your request for a resource. Multiple parameters can be added using the & symbol.

Example:

http://www.flipkart.com/watches?type=digital&rating=4

Here, type=digital and rating=4 are query parameters that help filter the watches being requested.


3. Understanding HTTP Requests and Responses

When a client (like your browser) requests a web resource, it sends an HTTP Request. The server responds with an HTTP Response. Let’s break down each of these.

3.1 HTTP Requests

An HTTP request consists of three parts:

  • Start Line: Contains the HTTP method (GET, POST, etc.), the URL, and the HTTP version.

  • Headers: Carry additional information like the content type and cookies.

  • Body: Optional data, usually for methods like POST, which send data to the server.

3.1.1 Start Line

The Start Line includes:

  • URL: The resource being requested.

  • HTTP Method: Indicates the action to be performed.

Common HTTP Methods:

  • GET: Retrieve data from the server.

  • POST: Send data to the server (e.g., form submissions).

  • PUT: Update an existing resource.

  • DELETE: Remove a resource from the server.

HTTP Versions:

The most common versions of HTTP are:

  • HTTP/1.1 (1997)

  • HTTP/2 (2015)

  • HTTP/3 (2019)

3.1.2 Headers

HTTP Headers carry metadata about the request or response, such as:

  • Content-Type: Specifies the format of the data being sent or received.

  • Authorization: Used for authentication purposes.

3.1.3 Body

The Body contains the data being sent to the server, often used with methods like POST or PUT. For instance, when a user submits a form, the data is included in the request body.


3.2 HTTP Responses

When a server receives a request, it sends back an HTTP response, which consists of:

  • Status Line: Provides the status of the request (success, error, etc.).

  • Headers: Contain information about the response.

  • Body: The resource or data requested by the client (if applicable).

3.2.1 Status Line

The status line includes:

  • HTTP Version

  • Status Code: Indicates whether the request was successful or if an error occurred.

  • Status Text: A human-readable explanation of the status.

Common Status Codes:

  • 2XX: Success (e.g., 200 OK, 201 Created)

  • 3XX: Redirection (e.g., 301 Moved Permanently)

  • 4XX: Client Errors (e.g., 404 Not Found, 401 Unauthorized)

  • 5XX: Server Errors (e.g., 500 Internal Server Error)

3.2.2 Body

The body of an HTTP response contains the data or resource that the client requested, such as an HTML page or JSON data from an API.


Conclusion

HTTP is the foundation of communication on the web. Understanding its structure—requests, responses, status codes, and headers—is essential for building modern web applications. By mastering HTTP, you’ll be better equipped to troubleshoot issues, build robust APIs, and create smoother interactions between clients and servers.


Thank you for reading! I hope this guide has been helpful in deepening your understanding of HTTP. Feel free to reach out if you have any questions or thoughts to share!

0
Subscribe to my newsletter

Read articles from EGA SAICHARAN directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

EGA SAICHARAN
EGA SAICHARAN