API Fundamentals Course
API Fundamentals
/
Advanced

Header Versioning

Definition

A versioning strategy where the URL remains exactly the same, but the client specifies which version of the API they want by sending a custom HTTP Header.

Explain Like I'm New

You only have one URL: `/api/users`. But when you send the request, you attach a sticky note (Header) that says 'Please give me the 2022 version of this data'. The server reads the sticky note and formats the data accordingly.

Real World Example

GitHub's API uses a custom Accept header: `Accept: application/vnd.github.v3+json`. Stripe uses a custom Stripe-Version header: `Stripe-Version: 2023-10-16`.

Common Use Cases

  • •Enterprise APIs
  • •REST purist design

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • Which versioning strategy is easier for a non-developer to test in a web browser: URL Versioning or Header Versioning?

intermediate

  • What is 'Content Negotiation' in the context of Header Versioning?

Flash Cards

Question

Easier to test?

Click to reveal answer
Answer

URL Versioning. You can just type `/v1/users` into Chrome and hit enter. To test Header versioning, you must use a tool like Postman or write code to manually attach the HTTP headers.

Question

Content Negotiation?

Click to reveal answer
Answer

It is the process where the client uses the `Accept` header to tell the server what format and version of data it wants, and the server negotiates to provide that exact format.