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

Authorization Header Patterns

Implement Bearer token, Basic auth, and API key patterns using the Authorization header.

Authorization Header Patterns

What you'll learn: How to securely pass credentials and tokens to REST APIs using the three most common Authorization header patterns.

The Core Idea

When your frontend needs to prove who the user is (or that it has permission to access an API), you send credentials through the Authorization HTTP header. This header follows specific patterns that servers expect—like showing your ID at different types of security checkpoints.

Think of it like entering a building: some places want to see your photo ID (Basic auth), others scan a badge you were given earlier (Bearer token), and some just need you to punch in a code (API key).

The Three Main Patterns

Bearer Token Pattern

The most common for modern APIs. You send a token (usually JWT or OAuth) that was issued after login:

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Used with tokens from OAuth, JWT sessions, or identity providers.

Basic Authentication Pattern

Sends a username and password encoded in Base64. The format is Basic base64(username:password):

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

Simple but requires HTTPS since Base64 is encoding, not encryption.

API Key Pattern

Some APIs use custom schemes where you prefix your API key:

Authorization: ApiKey abc123xyz789

Or sometimes just:

Authorization: Token abc123xyz789

The exact format depends on what the API documentation specifies.

Which Pattern When?

  • Bearer: For authenticated user sessions and OAuth flows
  • Basic: For simple service-to-service auth or development
  • API Key: For public API access limits and tracking

Key Takeaway: The Authorization header uses standardized patterns—Bearer for tokens, Basic for username/password, and custom schemes for API keys—to securely identify clients to REST APIs.