Content Negotiation
The code here demonstrates how content negotiation in JSON:API works.
Additionally, the code here provides
a custom "server-time" JSON:API extension that returns the local or UTC server time in top-level meta
.
- This extension can be used in the
Accept
andContent-Type
HTTP headers. - In a request body, the optional
useLocalTime
property in top-levelmeta
indicates whether to return the local or UTC time.
This feature is implemented using the following extensibility points:
- At startup, the "server-time" extension is added in
JsonApiOptions
, which permits clients to use it. - A custom
JsonApiContentNegotiator
chooses which extensions are active for an incoming request, taking the "server-time" extension into account. - A custom
IDocumentAdapter
captures the incoming request body, providing access to theuseLocalTime
property inmeta
. - A custom
IResponseMeta
adds the server time to the response, depending on the activated extensions inIJsonApiRequest
and the captured request body.