Header
ELI5 — The Vibe Check
Headers are the metadata attached to HTTP requests and responses — information about the information. Like the label on a package: who sent it, what's inside, how big it is, what language it's in. The actual content (body) is separate from the headers.
Real Talk
HTTP headers are key-value pairs that convey metadata about a request or response. Request headers include things like Authorization, Content-Type, Accept, and User-Agent. Response headers include Content-Type, Cache-Control, Set-Cookie, and CORS headers. Headers are case-insensitive.
Show Me The Code
// Reading and setting headers in Express
app.get('/data', (req, res) => {
// Read request headers
const auth = req.headers['authorization'];
const type = req.headers['content-type'];
// Set response headers
res.setHeader('X-Custom-Header', 'my-value');
res.setHeader('Cache-Control', 'max-age=3600');
res.json({ data: 'value' });
});
When You'll Hear This
"Set the Authorization header for the API request." / "Check the response headers for the rate limit info."
Related Terms
Content-Type
Content-Type is a header that tells the receiver what format the data is in. 'I'm sending you JSON.' 'I'm sending you a PNG image.' 'I'm sending you HTML.
Cookie
A cookie is a tiny piece of data the server tells your browser to store and send back on every future request.
HTTP (HyperText Transfer Protocol)
HTTP is the language your browser uses to ask websites for stuff. You type a URL, your browser shouts 'hey, give me that page!
Request
A request is what your browser (or app) sends to a server when it wants something. 'Give me the homepage.' 'Give me that image.
Response
A response is what the server sends back after receiving a request.