The Basics of HTTP Explained
Introduction to HTTP: Simplifying the Request-Response Model and Networking Jargon for Newbies
Communication in today's world relies heavily on networking, facilitating actions such as browsing websites and streaming content. Understanding how data travels across networks is crucial for anyone wishing to pursue a career in software engineering.
Hello, all! I'm Ikbal. This blog post will explore the basic principles of computer networking, HTTP protocols, the request-response model, and commonly used networking terms.
What is HTTP?
HTTP refers to the Hypertext Transfer Protocol. A protocol is a defined set of rules that governs communication. This is a stateless protocol utilized for exchanging data between a client (such as a browser) and a server.
Being stateless indicates that every request from the client (browser) to the server is handled as a separate interaction, without retaining any memory of previous requests.
HTTP Communication Model
This model includes both a client and a server.
Client: This refers to the device or application that requests a service (such as a web browser or a mobile application).
For example, your browser (acting as the client) sends a request to the https://courses.ikbal.com/ web server, seeking the content of the site (which may include the homepage, blog, or code editor).Server: The software or machine that answers your request or delivers the service related to the request.
For example, The https://courses.ikbal.com/ server gets your request and processes it. The server then transmits the requested data (HTML, CSS, JavaScript) to your browser, allowing it to show the page you were looking for.
Flipkart and Shopper Analogy:
When you click on a product, the Flipkart app or website (client software) sends a request to Flipkart’s server.
Flipkart's server then processes that request and returns the product information, pricing, and availability, which are shown on your display.
What is the Request-Response Cycle:-
The Request-Response Cycle is the fundamental process that governs the interaction between Client and Server.
The procedure starts when a client, which is usually a browser, creates an HTTP request to a server.
An HTTP request comprises:Request Line: Includes the HTTP method, the requested resource or URL, and the version of HTTP (for example, GET /home HTTP/1.1).
Headers: Pairs of keys and values that give extra information, such as browser details, date and time, and cookie storage.
Body (optional): The data being sent.
What does URL mean?
A URL (Uniform Resource Locator) indicates the position of a resource online and the method (protocol) used to access it. It functions like an address that informs the client (browser or application) where to direct the request and which resource to request.Common HTTP Methods: (Referred to as VERB)
GET: Retrieves data from the server.
POST: Submits data to the server.
PUT: Modifies existing data on the server.
DELETE: Removes data from the server.
PATCH: Partially modifies data.
When a server responds:
The server sends an HTTP response back to the client.
An HTTP response comprises:
Status Line: This includes the HTTP version, status code, and a brief description of the response (for instance, HTTP/1.1 200 OK).
Headers: These offer supplementary details regarding the response (such as Content-Type: text/html, Set-Cookie, etc.).
Body: This contains the actual data/content being returned (for example, HTML, JSON, or image data).
The status codes we observe here are part of the protocol established for servers.
The cycle concludes after the client has handled the response and rendered the content. Based on the circumstances, the client might start another request (such as navigating to a different page).
Beyond Basics: Exploring Sessions, Cache, and Cookies in the Request-Response Cycle
What exactly are sessions?
A session refers to a method of temporarily keeping track of user information on the server while they navigate through a website. You can imagine it as a "temporary storage" that the server uses to recognize your identity while you explore the site.
For instance: When you log into an online shopping platform, the server initiates a session to remember that you’re logged in, what products are in your shopping cart, and so on, until you either log out or close the browser.
Key Points:
Sessions are held on the server (rather than in the browser).
Sessions typically have a limited duration (for instance, they may expire after 15 minutes of no activity).
A session ID is frequently stored in a cookie to identify the user.
What are cookies?
Cookies are small data files that a website requests your browser to save on your device. These cookies assist websites in remembering you. They are returned to the server with every request made.
For instance: When you select "Remember me" during login, the website saves your login information in a cookie. The next time you visit, the website retrieves the cookie to log you in automatically.
Key Points:
Maintain user sessions (authentication).
Preserve user preferences (e.g., language choice).
Monitor user activity for analytics and advertising purposes.
What is a cache?
A cache refers to a method of temporarily saving website data in your browser to avoid the need for re-downloading. This process enhances the speed of website loading and reduces data consumption.
For instance: When you access a website for the first time, it retrieves images, CSS, and JavaScript files. These files are then stored in your browser's cache. When you revisit the site, your browser utilizes the cached files instead of fetching them anew.
Benefits of Cache:
It accelerates the loading time of websites.
Cache retains static content (such as images and stylesheets).
Session Cookie Cache and Train
Imagine you're getting onto a train.
Cookie: Your ticket contains your name, seat number, and travel information. Every time the Travelling Ticket Examiner (TTE) (server) checks, you show them your ticket, and they identify who you are. This ticket remains with you for the entirety of the trip (stored in your browser).
Cache: The schedule is displayed on a board at the train station. You don’t need to contact the railway company (server) multiple times to verify it—this saves time, as the schedule is kept locally (in your browser cache).
Session: The Travelling Ticket Examiner (TTE) (server) recognizes you during the trip, and remembers your seat and preferences. However, they forget everything about you once the journey concludes (the session expires).
Key Takeaway: Cookies accompany you, the cache retains frequently accessed information locally for quicker retrieval, and sessions provide temporary recognition but reset after the trip.
Conclusion
In this article, I explore the fundamentals of computer networking, concentrating on HTTP protocols, the request-response cycle, and key networking terminology. I describe how HTTP operates as a stateless protocol that facilitates data exchange between clients and servers and outlines the structure of requests and responses. I also discuss the role of URLs, popular HTTP methods, and the importance of status codes. Furthermore, I investigate more complex topics such as sessions, cookies, and caching, emphasizing their contributions to enhancing web interactions and refining user experience.