{"id":21605458,"url":"https://github.com/teaguestockwell/next-api-mw","last_synced_at":"2026-05-03T20:33:55.868Z","repository":{"id":57310565,"uuid":"427253961","full_name":"teaguestockwell/next-api-mw","owner":"teaguestockwell","description":"Compose middleware for Next.js API routes like React Hooks","archived":false,"fork":false,"pushed_at":"2022-06-07T02:31:14.000Z","size":458,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-05T12:55:33.280Z","etag":null,"topics":["nextjs","npm","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teaguestockwell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-12T06:20:13.000Z","updated_at":"2021-12-17T05:43:35.000Z","dependencies_parsed_at":"2022-08-27T04:21:42.620Z","dependency_job_id":null,"html_url":"https://github.com/teaguestockwell/next-api-mw","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/teaguestockwell/next-api-mw","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teaguestockwell%2Fnext-api-mw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teaguestockwell%2Fnext-api-mw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teaguestockwell%2Fnext-api-mw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teaguestockwell%2Fnext-api-mw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teaguestockwell","download_url":"https://codeload.github.com/teaguestockwell/next-api-mw/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teaguestockwell%2Fnext-api-mw/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32584061,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nextjs","npm","typescript"],"created_at":"2024-11-24T20:13:54.457Z","updated_at":"2026-05-03T20:33:55.852Z","avatar_url":"https://github.com/teaguestockwell.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![license-shield]][license-url] [![linkedin-shield]][linkedin-url] ![size-url] ![size-url2] [![npm-v]][npm-url] [![gh-shield]][gh-url]\n\n[license-shield]: https://img.shields.io/github/license/teaguestockwell/next-api-mw.svg\n\n[license-url]: https://github.com/teaguestockwell/next-api-mw/blob/master/LICENSE\n\n[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?logo=linkedin\u0026colorB=555\n\n[linkedin-url]: https://www.linkedin.com/in/teague-stockwell/\n\n[size-url]: https://img.shields.io/bundlephobia/minzip/next-api-mw\n\n[size-url2]: https://img.shields.io/bundlephobia/min/next-api-mw\n\n[npm-v]: https://img.shields.io/npm/v/next-api-mw\n\n[npm-url]: https://www.npmjs.com/package/next-api-mw\n\n[gh-shield]: https://img.shields.io/badge/-GitHub-black.svg?logo=github\u0026colorB=555\n\n[gh-url]: https://github.com/teaguestockwell/next-api-mw\n\u003c!-- PROJECT LOGO --\u003e\n\u003cbr /\u003e\n\u003cp align='center'\u003e\n  \u003ch3 align='center'\u003enext-api-mw\u003c/h3\u003e\n\n  \u003cp align='center'\u003e\n    Compose middleware for Next.js API routes like React Hooks\n  \u003c/p\u003e\n\u003c/p\u003e\n\n\u003c!-- TABLE OF CONTENTS --\u003e\n\u003cdetails open='open'\u003e\n  \u003csummary\u003e\u003ch2 style='display: inline-block'\u003eTable of Contents\u003c/h2\u003e\u003c/summary\u003e\n    \u003cli\u003e\u003ca href='#about-the-project'\u003eAbout The Project\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href='#getting-started'\u003eGetting Started\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href='#roadmap'\u003eRoadmap\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href='#contributing'\u003eContributing\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href='#run-the-tests'\u003eRun The Tests\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href='#license'\u003eLicense\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href='#contact'\u003eContact\u003c/a\u003e\u003c/li\u003e\n\u003c/details\u003e\n\n## About The Project\n\nConsuming API middleware should be as easy as using hooks in React. When using next-api-mw you can abstract common logic like auth or verifying query params into a middleware that can be used inside of an API route.\n\nWhen calling middleware inside your route, that middleware may either return a promise, or handle the request itself thereby stopping the rest of the handler and or middleware from running.\n\n## Getting Started\n\n```sh\nnpm i next-api-mw\n```\n\n```typescript\nimport { HandlerFactory, createMiddleware } from 'next-api-mw'\n\n// create one handler factory, then export it so you can create handlers for all your routes\nexport const handlerFactory = new HandlerFactory({\n  handleError: async ({req,res,e}) =\u003e {\n    res.status(500).json({ msg: 'server error' })\n  },\n  logger: async ({req,res,e}) =\u003e {\n\n  },\n  rootMiddleware: async ({req, res, end}) =\u003e {\n    if(req.url.includes('token')){\n      res.status(200).json({msg: 'token-accepted'})\n      end()\n    }\n  }\n})\n\n// middleware can be consumed in as many routes as you want\n// you can even use one middleware inside of another\nconst usingFooQS = createMiddleware(async ({req, res, end}) =\u003e {\n  const { foo } = req.query\n\n  if (!foo || typeof foo !== 'string') {\n    res.status(400).json({ msg: 'invalid foo' })\n    // the res will be sent and the remainder of this handler and the next middleware will not be evaluated\n    end()\n  }\n\n  return foo as string\n})\n\n// default export a handler in any file under page/api\nexport default handlerFactory.getHandler(async ({req, res, end}) =\u003e {\n  // you may consume middleware inside of get handler\n  const foo = await usingFooQS({req, res})\n  res.status(200).json({ foo })\n  end()\n})\n```\n## Roadmap\n\nSee the [open issues](https://github.com/teaguestockwell/next-api-mw/issues) for a list of proposed features (and known issues).\n\n## Contributing\nI'm open to all community contributions! If you'd like to contribute in any way\n\n## Run The Tests\nTests are E2E with Cypress. To get started run these commands: \n```sh\nnpm i\n```\n```sh\nnpm run dev\n```\n```sh\nnpm run test\n```\n## License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n## Contact\n\nTeague Stockwell - [LinkedIn](https://www.linkedin.com/in/teague-stockwell)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteaguestockwell%2Fnext-api-mw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteaguestockwell%2Fnext-api-mw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteaguestockwell%2Fnext-api-mw/lists"}