{"id":18557,"library":"middy-jsonapi","title":"Middy JSONAPI Middleware","description":"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.","status":"active","version":"2.0.2","language":"javascript","source_language":"en","source_url":"https://willfarrell@github.com/willfarrell/middy-jsonapi","tags":["javascript","middy","jsonapi","middleware"],"install":[{"cmd":"npm install middy-jsonapi","lang":"bash","label":"npm"},{"cmd":"yarn add middy-jsonapi","lang":"bash","label":"yarn"},{"cmd":"pnpm add middy-jsonapi","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: required as the core middleware framework","package":"middy","optional":false}],"imports":[{"note":"Package is ESM-only since v2. Use import or dynamic import.","wrong":"const jsonapi = require('middy-jsonapi')","symbol":"jsonapi","correct":"import jsonapi from 'middy-jsonapi'"},{"note":"The package exports a default function, not a named export.","wrong":"import { jsonapi } from 'middy-jsonapi'","symbol":"middleware","correct":"import jsonapi from 'middy-jsonapi'"},{"note":"TypeScript: use default import with esModuleInterop or use namespace import if types allow.","wrong":"import * as jsonapi from 'middy-jsonapi'","symbol":"TypeScript","correct":"import jsonapi from 'middy-jsonapi'"}],"quickstart":{"code":"import middy from 'middy';\nimport jsonapi from 'middy-jsonapi';\n\nconst handler = middy(async (event, context) => {\n  return {\n    statusCode: 200,\n    body: JSON.stringify({\n      data: { type: 'articles', id: '1', attributes: { title: 'Hello' } }\n    })\n  };\n});\n\nhandler.use(jsonapi({\n  response: {\n    jsonapi: { version: '1.0' },\n    meta: { version: '1.0.0', copyright: '2023' }\n  }\n}));\n\n// Example invocation (AWS Lambda event)\nconst event = {\n  httpMethod: 'GET',\n  headers: { Accept: 'application/vnd.api+json' },\n  queryStringParameters: { include: 'author', page: '1' }\n};\nhandler(event, {}).then(res => console.log(res));","lang":"typescript","description":"Shows how to import, configure, and use middy-jsonapi with a basic handler and optional response metadata."},"warnings":[{"fix":"Use import jsonapi from 'middy-jsonapi' or use dynamic import().","message":"In v2.0.0, the package switched to ESM-only. CommonJS require() will fail.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure httpContentNegotiation or a custom middleware sets the Accept header to the required media type.","message":"The Accept header must be exactly 'application/vnd.api+json' or the middleware may not process response correctly.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider using an alternative caching mechanism or check compatibility.","message":"The 'cache' middleware from middy is optionally used but may be removed in future versions.","severity":"deprecated","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install middy-jsonapi and ensure you use import (ESM) not require().","cause":"Package not installed or incorrect import path (CommonJS require used with ESM package).","error":"Cannot find module 'middy-jsonapi'"},{"fix":"Use import jsonapi from 'middy-jsonapi' without curly braces.","cause":"Attempted to import named export { jsonapi } from 'middy-jsonapi' but only default export exists.","error":"TypeError: jsonapi is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}