Introduction
Hello! Welcome to the final lesson in our module on "How the Web Works."
In our last few lessons, we've built a solid picture of how a client (like your browser) communicates with a server. You know that to ask for something, the client specifies a URL (the address) and an HTTP method (the action, like GET or POST). You also learned how the server replies with an HTTP status code (the outcome, like 200 OK or 404 Not Found).
But there's more to the conversation. Both the request and the response carry extra information—metadata that helps both sides understand the context of the communication. This metadata is sent in HTTP headers.
Think of an HTTP message as a package being mailed. The main content of the message is called the body (the letter inside the envelope). The headers are like the information written on the outside of the envelope: the "to" and "from" addresses, a "fragile" sticker, or instructions for the mail carrier. This information isn't the main content, but it's essential for getting the package delivered and handled correctly.

In this lesson, you will learn to explain what headers are and their purpose in HTTP requests and responses. We'll look at the most common headers you'll encounter when working with APIs. This is the final piece of the puzzle for understanding the fundamentals of web communication.
What are HTTP Headers?
At their core, HTTP headers are additional pieces of information sent with every HTTP request and response. They provide context and instructions for both the client and the server.
To get a simple analogy for this concept, let's watch the beginning of the following video.
How to use headers in REST APIs? Different types of headers, how and where to use?
The video 'How to use headers in REST APIs?' uses a great analogy of an envelope to explain the role of headers as metadata for a request or response.
Watch the first 2 minutes and 8 seconds of this video (from 0:00 to 2:08). Focus on understanding how headers are like the information on an envelope, while the body is the content inside.
As the video explained, headers are metadata. To see how they are structured, let's turn to a quick reading.
The article 'What are HTTP headers?' from DebugBear provides a clear, concise definition and examples of how headers are formatted.
Read the sections 'What are HTTP headers?' and 'HTTP headers explained'. Pay attention to the key-value pair format (e.g., Content-Type: text/html) and the distinction between request and response headers.
From that reading, you now know two key things:
- Headers are simple key-value pairs, like
Name: Value. - They are separated into two main types: Request Headers and Response Headers.
Let's explore each of these types with practical examples.
Seeing Headers in Postman
Before we dive into specific headers, it's helpful to see where they live in Postman, the tool you'll be using. The next video will give you a tour and introduce a few important headers.
Postman Tutorial #16 - Headers in Postman | Postman Headers Explained
This video, 'Headers in Postman', demonstrates exactly where to find and how to use headers within Postman. It uses a helpful parcel analogy to reinforce the concept.
Watch the video from the beginning to 6:24. Pay close attention to: Where the 'Headers' tab is for both the request and the response. The explanation of the Content-Type header and how it automatically changes based on the body format you select in Postman (e.g., JSON vs. Text).
This practical demonstration is key. You saw that Postman often adds some headers automatically, and that the Content-Type header is crucial for telling the server what kind of data you're sending in the request body.
Common Headers and Their Purpose
Now, let's look at some of the most common headers you'll encounter. They act as the "rules of engagement" for an API call.
Request Headers (Client → Server)
These headers are sent by the client to provide the server with more information about the request.
Content-Type: Tells the server the format of the data in the request body. This is essential forPOSTandPUTrequests. If you're sending JSON, the header would beContent-Type: application/json.Accept: Tells the server which data format(s) the client can understand for the response. A client might sendAccept: application/jsonto say, "Please send me the response in JSON format if you can." This is how content negotiation happens.User-Agent: Identifies the client software making the request. It could be a browser (Mozilla/5.0...), Postman (PostmanRuntime/7.29.2), or a Python script (python-requests/2.28.1). This can be useful for analytics or for the server to tailor its response.Authorization: Carries credentials to authenticate a client with a server. For example, it might hold an API key or a token. We will cover this in great detail in a future module on API security.
Response Headers (Server → Client)
These headers are sent back by the server to give the client more information about the response.
Content-Type: Just like the request header, this tells the client the format of the data in the response body. For most modern APIs, this will beContent-Type: application/json.Content-Length: Specifies the size of the response body in bytes. This helps the client know how much data to expect.Date: The date and time the response was generated by the server.Server: Information about the server's software (e.g.,nginx/1.18.0).
To solidify your understanding of these specific headers, please read through the following list of examples.
The 'Examples of HTTP headers' section in the DebugBear article provides clear explanations for some of the most common request and response headers.
Read the section titled 'Examples of HTTP headers'. Focus on the explanations for User-Agent and Accept under 'Request Headers', and Content-Type under 'Response Headers'. You can skim the other examples like Cookie and Cache-Control for now, as they are less critical for your immediate goals.
Custom Headers
While there is a standard set of headers, APIs can also define their own custom headers for specific purposes. These are often prefixed with X- to distinguish them from standard headers (e.g., X-Rate-Limit-Remaining). These are used to pass application-specific information that doesn't fit into the standard headers.
You can add any custom headers you need in the same 'Headers' tab in Postman.
Conclusion
Congratulations on completing the first module! You've built a strong foundation for understanding how the web works, which is essential for learning about APIs.
Key Takeaways from this Lesson:
- HTTP Headers are key-value pairs that carry metadata with requests and responses.
- Request Headers are sent by the client to give the server context (e.g.,
Content-Type,Accept,Authorization). - Response Headers are sent by the server to give the client context (e.g.,
Content-Type,Content-Length). - Headers are fundamental for content negotiation, authentication, caching, and more.
- Tools like Postman and browser developer tools allow you to inspect and modify headers for testing and debugging.
Module 1 Recap:
Over the last six lessons, you have learned about:
- The client-server model.
- The role of HTTP as the communication protocol.
- The structure of a URL.
- The primary HTTP methods (
GET,POST,PUT,DELETE). - How to interpret HTTP status codes.
- The purpose of HTTP headers.
You are now fully equipped with the vocabulary and concepts needed to dive into the world of APIs.
In our next lesson, we will begin the "API Fundamentals" module, where you will finally learn to define what an API is and see how it uses all the HTTP principles you've just mastered.