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.
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.