Course contentsShow
← JavaScript
Lesson 2282 of 2,72347. Networking PrimitivesFree lesson

Common HTTP Headers

Essential headers like Content-Type, Authorization, Accept, and when to use each one.

Common HTTP Headers

You'll learn which HTTP headers are essential for most requests and responses, and when to use each one.

The Most Important Headers

Think of HTTP headers as specialized envelopes for your data — each one tells the server (or browser) something specific about what you're sending or what you expect back.

Content-Type

Tells the recipient what format your data is in:

const headers = new Headers();
headers.set('Content-Type', 'application/json');
// "This body is JSON data"

Use when sending data in a request body. Common values: application/json, text/plain, multipart/form-data, application/x-www-form-urlencoded.

Accept

Tells the server what formats you're willing to receive:

headers.set('Accept', 'application/json');
// "I prefer JSON responses"

This guides servers that can return multiple formats (like APIs that support JSON, XML, or plain text).

Authorization

Provides credentials to access protected resources:

headers.set('Authorization', 'Bearer abc123token');
// "Here's my key to access this resource"

Common patterns: Bearer <token>, Basic <base64>, or custom schemes. Always required for authenticated endpoints.

Cache-Control

Instructs how responses should be cached:

headers.set('Cache-Control', 'no-cache');
// "Always check with the server before using cached data"

Values like max-age=3600, no-store, or must-revalidate control browser and proxy caching behavior.

When to Use Each

  • Content-Type: Every request with a body
  • Accept: When you need specific response formats
  • Authorization: For protected endpoints
  • Cache-Control: When freshness matters (or when debugging cache issues)

Key Takeaway: Master these four headers — Content-Type describes what you're sending, Accept describes what you want back, Authorization proves who you are, and Cache-Control manages freshness.