What is the Location header?
The Location response header serves two main functions: redirecting the client to a new URL, or pointing to the URI of a newly created resource.
API Usage & Best Practices
- Use on 201 Created: When a resource is successfully created via POST, always include the Location header pointing to the GET path of the new resource.
- Relative references resolve against the target URI: RFC 9110 defines the value as a URI-reference, so
Location: /v1/leads/lead_123is valid and the client resolves it against the request’s target URI. Absolute URLs remove any doubt about which host and scheme a client lands on behind proxies, so prefer them when your public origin differs from what the application sees. - Fragments carry over on redirects: If a
Locationin a 3xx response has no fragment, the user agent keeps the fragment of the original reference. A link to/docs#auththat is redirected withLocation: /v2/docsends up at/v2/docs#auth. - Not the same as Content-Location:
Locationpoints at a different resource: the one created by a201, or the redirect target of a 3xx.Content-Locationidentifies the resource whose representation is in this response’s body. Do not use one in place of the other.
Examples
HTTP/1.1 201 CreatedLocation: https://api.apiguide.dev/v1/leads/lead_123