Registry / aws / middy-jsonapi

middy-jsonapi

JSON →
library2.0.2jsnpmunverified

middy-jsonapi (v2.0.2) is a middleware for the Middy Node.js AWS Lambda framework that formats Lambda responses to conform to the JSON API spec (jsonapi.org). It parses query parameters like include, fields, sort, and page, supports page-based and offset-based pagination with auto-generated links, and formats errors into standard JSON API error objects. Unlike manual formatting, it integrates seamlessly with Middy's middleware chain (e.g., validator, httpContentNegotiation) and works with strict Accept headers (application/vnd.api+json). Requires middy as a peer dependency. Active development, release cadence irregular.

npm install middy-jsonapi
INSTALL
IMPORT
SIG · MIDDY-JSONAPI
M
middy-jsonapi
awsjavascriptv2.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

jsonapi
import jsonapi from 'middy-jsonapi'
const jsonapi = require('middy-jsonapi')
Package is ESM-only since v2. Use import or dynamic import.
middleware
import jsonapi from 'middy-jsonapi'
import { jsonapi } from 'middy-jsonapi'
The package exports a default function, not a named export.
TypeScript
import jsonapi from 'middy-jsonapi'
import * as jsonapi from 'middy-jsonapi'
TypeScript: use default import with esModuleInterop or use namespace import if types allow.

Shows how to import, configure, and use middy-jsonapi with a basic handler and optional response metadata.

import middy from 'middy'; import jsonapi from 'middy-jsonapi'; const handler = middy(async (event, context) => { return { statusCode: 200, body: JSON.stringify({ data: { type: 'articles', id: '1', attributes: { title: 'Hello' } } }) }; }); handler.use(jsonapi({ response: { jsonapi: { version: '1.0' }, meta: { version: '1.0.0', copyright: '2023' } } })); // Example invocation (AWS Lambda event) const event = { httpMethod: 'GET', headers: { Accept: 'application/vnd.api+json' }, queryStringParameters: { include: 'author', page: '1' } }; handler(event, {}).then(res => console.log(res));
Debug
Known issues
breakingIn v2.0.0, the package switched to ESM-only. CommonJS require() will fail.
fix
Use import jsonapi from 'middy-jsonapi' or use dynamic import().
affects: >=2.0.0
gotchaThe Accept header must be exactly 'application/vnd.api+json' or the middleware may not process response correctly.
fix
Ensure httpContentNegotiation or a custom middleware sets the Accept header to the required media type.
affects: >=1.0.0
deprecatedThe 'cache' middleware from middy is optionally used but may be removed in future versions.
fix
Consider using an alternative caching mechanism or check compatibility.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'middy-jsonapi'
Package not installed or incorrect import path (CommonJS require used with ESM package).
fix
Run npm install middy-jsonapi and ensure you use import (ESM) not require().
TypeError: jsonapi is not a function
Attempted to import named export { jsonapi } from 'middy-jsonapi' but only default export exists.
fix
Use import jsonapi from 'middy-jsonapi' without curly braces.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
middyrequiredPeer dependency: required as the core middleware framework
Agent activity
8 hits · last 30 days
node
8
Resources
middy-jsonapi — npm install middy-jsonapi · libregistry