Raghu
Raghu

Reputation: 3079

When to use Location http header versus Link http header in API responses?

I am used to sending http(s) link value in Location http response header. However there appears to be a new standard that improves on this Location header with a new Link http response header, as described in https://datatracker.ietf.org/doc/html/rfc5988#section-5.

Do both of them address the same problem? If so, when should I use one over the other?

Upvotes: 0

Views: 642

Answers (1)

Evert
Evert

Reputation: 99687

The Location header has a a specific meaning: it should point to the destination of a redirect, or it should point to a newly created resource in conjunction with a 201 Created response.

The Link header should be used for other kinds of relationships. The Link header supports many types of relationship, for example:

  • Pointing to the author of a resource
  • Pointing to a stylesheet that may be used with a resource.
  • Pointing to a collection that a resource belongs in
  • Pointing to the predecessor-version of a resource
  • Pointing to the next page.

The full list of these relationship types can be found on the IANA Link Relations page

Upvotes: 1

Related Questions