Course contentsShow
← Web Development
Lesson 1497 of 2,98227. REST API Design for FrontendFree lesson

Common HTTP Request Headers

Learn essential request headers like Accept, Authorization, Content-Type, and User-Agent used in frontend requests.

Common HTTP Request Headers

You'll learn the most important HTTP headers that frontend applications send to REST APIs, and what each one tells the server.

When your frontend code makes an HTTP request, it doesn't just send the URL and method—it also sends headers: key-value pairs that provide context about the request. Think of headers like the envelope information on a letter: they tell the recipient important details before the actual message is read.

The Essential Request Headers

Accept

The Accept header tells the server what content types your client can understand. For example, Accept: application/json means "I want JSON back." The server uses this to format its response appropriately.

Authorization

The Authorization header carries credentials to authenticate your request. Common patterns include Authorization: Bearer <token> for JWT tokens or Authorization: Basic <credentials> for basic auth. Without proper authorization, APIs will typically return 401 or 403 status codes.

Content-Type

When you're sending data (like in POST or PUT requests), Content-Type tells the server what format your request body is in. Content-Type: application/json means you're sending JSON data, while Content-Type: application/x-www-form-urlencoded indicates form data.

User-Agent

The User-Agent header identifies your client application and browser. It looks like User-Agent: Mozilla/5.0... and helps servers understand what kind of device/browser is making the request. This can be useful for analytics or serving device-specific content.

Why Headers Matter

These headers create a contract between your frontend and the API. They prevent confusion about data formats, enable security through authentication, and help servers respond appropriately to different clients.

Key Takeaway: Request headers like Accept, Authorization, Content-Type, and User-Agent provide essential metadata that tells REST APIs how to interpret and respond to your frontend requests.