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
AcceptandContent-TypeHTTP headers. - In a request body, the optional
useLocalTimeproperty in top-levelmetaindicates 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
JsonApiContentNegotiatorchooses which extensions are active for an incoming request, taking the "server-time" extension into account. - A custom
IDocumentAdaptercaptures the incoming request body, providing access to theuseLocalTimeproperty inmeta. - A custom
IResponseMetaadds the server time to the response, depending on the activated extensions inIJsonApiRequestand the captured request body.