0

The company I work for has several products that consume shared APIs. Previously we've passed the 'product-code' as a custom HTTP header. It's generally only used for things like determining a product-specific API key, or included in certain log messages, etc. It's generally not persisted to a database.

Recently we've started adopting the JSON-API spefification for building APIs.

Would the recommendation be to use meta information to specify the 'product-code', or to keep this as a custom HTTP header?

Cheers.

Ryan.Bartsch
  • 3,698
  • 1
  • 26
  • 52
  • Is this `product-code` currently sent as a request or response HTTP header? Is it set by the client on the request or by the server on the response? Is it resource specific? I mean does one resource (unique combination of type and ID) have always the same value for `product-code`? – jelhan Aug 22 '20 at 11:00
  • it's on the request. It's probably something that could be included in all operations... – Ryan.Bartsch Aug 23 '20 at 22:05

1 Answers1

1

Would the recommendation be to use meta information to specify the 'product-code', or to keep this as a custom HTTP header?

It's totally fine to use a custom HTTP header with an API which implements JSON:API specification.

The meta property allows to include meta information on per JSON:API document, per resource object or per relationship of a resource object basis. It can only be included in requests and response, which include a JSON:API document.

Your use case does not fit well with the meta property. If I got it right from your comment it should be possible to include the product-code information with every request. But not all requests have a JSON:API document, in which meta section you could include it. For example neither fetch (GET) nor delete requests for resources include a JSON:API document as request body.

jelhan
  • 6,149
  • 1
  • 19
  • 35