restify-jsonapi
Package comprise JSON:API plugins and formatter for the restify server.
Plugins
JSONAPIRequest
The plugin sends response with '415 Unsupported Media Type' status code if the request specifies the header Content-Type: application/vnd.api+json with any media type parameters, or sends response '406 Not Acceptable' status code if a request’s Accept header contains the JSON:API media type and all instances of that media type are modified with media type parameters, otherwise calls the next().
const restify = ;const JSONAPIRequest = pluginsJSONAPIRequest; const server = restify;server;
JSONAPIResponse
The plugin attaches 'application/vnd.api+json' header to every response.
const restify = ;const JSONAPIResponse = pluginsJSONAPIResponse; const server = restify;server;
Formatter
The formatter converts given data to a JSON string.
const restify = ;const restifyJSONAPI = ; const formatJSONAPI = restifyJSONAPIformatJSONAPI;const mediaType = restifyJSONAPIJSONAPIMediaType; const server = restify;server;
If the data is an instance of the Error, the formatter converts it to appropriate 'application/vnd.api+json' string. Result will be like that
errors: status: datastatusCode code: dataname title: datamessage
If the data includes 'errors' field, every element of the 'errors' will be converted into the object like above, and the data will be converted into JSON string. Otherwise the data will be converted into JSON string.