Registry / devops / restify-formatter-jsonapi

restify-formatter-jsonapi

JSON →
library2.0.0jsnpmunverified

A Restify formatter for JSON API compliant responses using the `application/vnd.api+json` content type. Version 2.0.0 supports Restify 5.x. It is a lightweight plugin that integrates directly into Restify's formatter chain. The package currently handles basic JSON API serialization but lacks support for links, meta, included resources, and the jsonapi section (roadmap). It is a niche tool for Restify users who need strict JSON API compliance, with limited maintenance activity.

npm install restify-formatter-jsonapi
INSTALL
IMPORT
SIG · RESTIFY-FORMATTER-
R
restify-formatter-jsonapi
devopsjavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const formatter = require('restify-formatter-jsonapi');
import formatter from 'restify-formatter-jsonapi';
Package is CommonJS only; ESM import will fail.
default
server.formatters['application/vnd.api+json'] = formatter;
server.formatters['application/json'] = formatter;
Must register under the correct MIME type 'application/vnd.api+json'.
default
server.use(restify.plugins.acceptParser(server.acceptable)); server.acceptable.push('application/vnd.api+json');
Missing acceptParser setup or not pushing the media type to acceptable array.
The formatter only activates if the client sends Accept: application/vnd.api+json and the server has it configured as acceptable.

Sets up a basic Restify server with JSON API formatter, including accept parser and media type registration, then serves a sample resource.

const restify = require('restify'); const server = restify.createServer(); // Add accept parser server.use(restify.plugins.acceptParser(server.acceptable)); server.acceptable.push('application/vnd.api+json'); // Register the JSON API formatter const jsonapiFormatter = require('restify-formatter-jsonapi'); server.formatters['application/vnd.api+json'] = jsonapiFormatter; // Example handler returning a JSON API documented resource server.get('/api/resource', (req, res, next) => { const data = { id: '1', type: 'resource', attributes: { name: 'Example' } }; res.json(200, { data }); next(); }); server.listen(8080, () => console.log('Server listening'));
Debug
Known issues
gotchaRequires Restify 5.x; incompatible with Restify 6+ or 4.x.
fix
Check your Restify version. If using Restify 6+, find an alternative or fork.
affects: 2.0.0
gotchaThe formatter does NOT handle included resources, links, meta, or jsonapi top-level members. The response is a raw JSON object with data key. Incomplete JSON API compliance.
fix
Manually construct the full JSON API envelope in your route handlers, or use a more complete library like jsonapi-store-relationaldb.
affects: >=1.0.0
gotchaMust add 'application/vnd.api+json' to server.acceptable array after acceptParser middleware; otherwise the formatter won't be invoked.
fix
Push the media type to server.acceptable and ensure acceptParser is registered.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: server.formatters['application/vnd.api+json'] is not a function
Trying to register the module directly without calling require at the proper point, or using a wrong import method (e.g., ESM import).
fix
Use const formatter = require('restify-formatter-jsonapi'); and then assign server.formatters['application/vnd.api+json'] = formatter;
Error: cannot GET /api/resource (406 Not Acceptable)
The Accept header is not set to 'application/vnd.api+json' or the media type is not in server.acceptable.
fix
Add server.acceptable.push('application/vnd.api+json'); after registering acceptParser.
restify-formatter-jsonapi: Version 2.0.0 requires restify@5.x.x, but you have restify@6.0.0
Incompatible peer dependency version of Restify.
fix
Downgrade to restify@5.x or use a different formatter library that supports Restify 6+.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
restifyrequiredpeer dependency required at runtime for formatter registration
Agent activity
2 hits · last 30 days
node
2
Resources
restify-formatter-jsonapi — npm install restify-formatter-jsonapi · libregistry