Hello! Let's dive into our second lesson.
Introduction
In our last lesson, we explored the client-server model and saw how a browser (the client) communicates with a server to get a webpage. We broke down the process into several key steps: a DNS lookup to find the server's address, establishing a TCP connection to create a communication line, and finally, sending an HTTP request to ask for the page.
Today, we're going to zoom in on that final, crucial piece: HTTP. This lesson will explain what HTTP is and its fundamental role in all web communication, including the APIs you want to learn. By the end of our session, you'll be able to describe what HTTP is and understand the structure of the messages that clients and servers exchange. This knowledge is the bedrock for interacting with any web API.
What is HTTP? The Language of the Web
HTTP stands for HyperText Transfer Protocol. That might sound complex, but you can think of it simply as the language or set of rules that web clients and servers use to talk to each other.
Imagine you're trying to communicate with someone who only speaks French. To be understood, you also have to speak French. It's the same on the web: a web server is programmed to understand messages formatted according to the rules of HTTP. When your browser sends a request, it must be an HTTP request, otherwise the server won't understand what it wants.
One of the most surprising things about HTTP is that at its core, it's just plain text. Let's watch a short video that makes this point very clearly.
Web Server Concepts and Examples
This video from WebConcepts explains that HTTP is fundamentally a simple, text-based protocol. This is a key insight that demystifies a lot of how the web works.
Please watch from 04:30 to 05:27. Focus on the core idea that HTTP messages are just structured, human-readable text.
This text-based nature is what makes HTTP so versatile and is a key reason for its success.
The Request-Response Cycle
As we touched on in the last lesson, communication in HTTP happens in a request-response cycle. The client always initiates the conversation by sending a request, and the server replies with a response.

A Stateless Protocol
A critical characteristic of HTTP is that it is stateless. This means the server does not remember anything about past requests. Each request from a client is treated as a brand-new, independent interaction. If you request a page and then request it again one second later, the server has no memory of your first request.
This might seem strange, especially since websites clearly "remember" us when we log in. This is achieved by building state on top of HTTP using mechanisms like cookies and sessions, which we will explore later in the course. For now, just remember that the underlying HTTP protocol itself is stateless.
Let's read a short article that provides a great summary of these core concepts and explicitly connects them to the world of APIs.
What is HTTP and how do HTTP requests and responses work in web architecture
This article from Designgurus.io provides a concise definition of HTTP, its request-response model, and its stateless nature, while also highlighting its importance for APIs.
Read the section titled 'What is HTTP?'. It reinforces the key definitions we've just discussed.
The Anatomy of HTTP Messages
Now that we have a high-level understanding of HTTP, let's dissect the messages themselves. Both requests and responses share a similar structure, typically consisting of three parts.
To get a visual walkthrough of this structure, let's watch another short video.
What is HTTP? How the Internet Works! #1
This video from FollowAndrew breaks down the components of both an HTTP request and an HTTP response, explaining the purpose of each part.
Watch from 05:11 to 06:58, and then from 08:47 to 11:35. Pay close attention to the three main parts of a request and a response: the start-line, the headers, and the body.
Let's formalize what the video explained.
The HTTP Request
A request is a text message a client sends to a server. It's composed of:
-
Request Line: The first line, which specifies:
- Method: The action to be performed (e.g.,
GETto retrieve data,POSTto send data). - Target: The path to the resource on the server (e.g.,
/products/123). - HTTP Version: The version of the protocol being used (e.g.,
HTTP/1.1).
- Method: The action to be performed (e.g.,
-
Headers: A series of key-value pairs that provide additional information about the request. For example:
Host: www.example.com: The domain of the server.User-Agent: Chrome/125.0: Information about the client software.
-
Body: An optional block of data. This is used with methods like
POSTto send data to the server, such as the contents of a form or a JSON object for an API call.GETrequests do not have a body.
The HTTP Response
A response is the server's reply. It's also a text message, composed of:
-
Status Line: The first line, which contains:
- HTTP Version: The version of the protocol.
- Status Code: A 3-digit number indicating the outcome of the request (e.g.,
200for success,404for not found). - Status Text: A brief, human-readable description of the status code (e.g.,
OK,Not Found).
-
Headers: Key-value pairs providing information about the response. For example:
Content-Type: text/html: The type of data in the body.Content-Length: 1254: The size of the body in bytes.
-
Body: The actual resource that was requested. For a webpage, this is the HTML document. For an API call, this is often data formatted as JSON.
To see this structure written down clearly, let's refer back to our reading.
What is HTTP and how do HTTP requests and responses work in web architecture
This section of the Designgurus.io article provides a clear, text-based breakdown of the request and response structures we just saw in the video.
Read the section 'HTTP Requests and Responses Explained'. This will solidify your understanding of the different parts of each message.
Seeing HTTP in Action
Theory is great, but it's even better to see this happening live. Your own web browser gives you tools to inspect the HTTP traffic for any website you visit. The following video demonstrates how to use these "Developer Tools."
What is HTTP? How the Internet Works! #1
Let's watch the final part of the FollowAndrew video, where he uses the Firefox Developer Tools to show you what real HTTP requests and responses look like for a webpage.
Watch from 12:55 to 16:41. You don't need to follow along by opening the tools yourself just yet. The goal is to see how a single page load generates many HTTP requests and to visually identify the request/response headers and status codes we've been discussing.
As you saw, even a simple page load involves dozens of request-response cycles to fetch the main HTML document, plus all of its images, stylesheets, and scripts. This is the engine that drives the entire web.
Conclusion
Excellent work! You've now demystified the language of the web. This foundation is absolutely essential for understanding how to consume and build APIs.
Here are the key takeaways from today's lesson:
- HTTP is the protocol, or "language," that clients and servers use to communicate on the web.
- It operates on a stateless request-response model, where the client asks and the server answers.
- HTTP messages (requests and responses) are structured text composed of a start-line, headers, and an optional body.
- The request specifies the action (method) and the resource (target).
- The response provides the outcome (status code) and the content (body).
- For APIs, the body of the response typically contains data formatted in JSON, rather than HTML.
In our next lesson, we will dig into one specific part of the request: the URL. We'll learn how to break it down into its components to understand exactly how we tell a server which resource we want.