🌐HTTP Basics: An Easy-to-Follow Guide

HTTP, short for Hypertext Transfer Protocol, is used for transmitting hypermedia documents like HTML. It is the protocol that web browsers and web servers use to communicate. HTTP follows a client-server model where the client (usually a web browser) makes a request to the server, and the server responds with the requested resource.

How does HTTP work?

HTTP consists of the following parts:

  1. Request-Response Cycle

  2. HTTP Headers

  3. HTTP Methods

  4. HTTP Status Codes

Let's go through them one by one:

🔁The Request-Response Cycle

It's essentially how we connect a frontend and backend. The client (a web browser) sends a request to the server, and the server responds with the requested information. The request includes what the client wants, and the server generates a response based on that request.


🎩HTTP Headers

HTTP headers are metadata, meaning data in key:value pairs, sent along with the request and response. These headers handle functions like caching, authentication, session management, and more.

Some categories of these headers are:

  • Request Headers - From Client

  • Response Headers - From Server

  • Representation Headers - Encoding/Compression

  • Payload Headers - Data

Some Common Headers:

  • Accept - Type of data accepted by the client (e.g., application/json)

  • User-Agent - Indicates which application the request came from

  • Authorization - Bearer JWT tokens and similar

  • Content-Type - Type of data in the response body (e.g., image, pdf, json)

  • Cookies

  • Cache-Control


⛓️‍💥HTTP Methods

These are some basic operations used to interact with the server.

Some of them are:

  1. GET - Retrieves a resource.

  2. HEAD - Similar to GET, but retrieves only response headers, not the body.

  3. OPTIONS - Lists available operations.

  4. TRACE - Performs a loopback test (gets some data).

  5. DELETE - Removes a resource.

  6. PUT - Replaces a resource.

  7. POST - Interacts with the resource (often adds something).

  8. PATCH - Changes part of a resource.


🔢HTTP Status Codes

HTTP responses include status codes that indicate the outcome of the request. These codes are grouped into five categories:

  1. 1xx - Informational, regarding the request processing

  2. 2xx - Success, the desired work was successfully done (Ex: request received suucessfully)

  3. 3xx - Redirection, Further action required to complete the request

  4. 4xx - Client Error, There's some problem with the request maybe syntax or data or as such on client-side.

  5. 5xx - Server Error, The server failed to fulfill a valid request

Some commonly used Status Codes are:

STATUS CODEUSAGE
100Continue
102Processing
200OK
201Created
202Accepted
307Temporary Redirect
308Permanent Redirect
400Bad Request
401Unauthorized
402Payment Required
404Not Found
500Internal Server Error
504Gateway Time Out

Conclusion

Understanding the basics of HTTP is crucial for anyone involved in web development. This protocol is the backbone of the web, enabling communication between clients and servers. By learning the fundamentals of HTTP methods, status codes, headers, and the structure of requests and responses, you'll be well on your way to mastering web development.

Whether you're building a simple website or developing a complex web application, a solid understanding of HTTP will provide a strong foundation for your journey. Happy coding!


Make sure to provide any feedback or views regarding this blog in comment section! :)

20
Subscribe to my newsletter

Read articles from AYUSH KUMAR GUPTA directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

AYUSH KUMAR GUPTA
AYUSH KUMAR GUPTA

I'm a college student specializing in Full Stack Web Development, with a solid grasp of programming fundamentals and expertise in C,C++, Java, JavaScript and Python. Passionate about crafting seamless digital experiences, I'm on a quest to understand the intricacies of web development from backend to frontend. Eager to connect with individuals and organizations that share a zeal for innovation and learning in tech