{"id":15683410,"url":"https://github.com/filp/next-better-api","last_synced_at":"2025-10-07T02:45:09.238Z","repository":{"id":57046404,"uuid":"499918172","full_name":"filp/next-better-api","owner":"filp","description":"Opinionated TypeScript-first helpers for better NextJS APIs","archived":false,"fork":false,"pushed_at":"2022-08-24T10:18:15.000Z","size":127,"stargazers_count":10,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-19T15:47:40.783Z","etag":null,"topics":["api","helper","nextjs","schema","typescript","zod"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/next-better-api","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/filp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-04T19:25:57.000Z","updated_at":"2023-11-24T19:59:52.000Z","dependencies_parsed_at":"2022-08-24T03:40:25.005Z","dependency_job_id":null,"html_url":"https://github.com/filp/next-better-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/filp/next-better-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filp%2Fnext-better-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filp%2Fnext-better-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filp%2Fnext-better-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filp%2Fnext-better-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/filp","download_url":"https://codeload.github.com/filp/next-better-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filp%2Fnext-better-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278710890,"owners_count":26032541,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["api","helper","nextjs","schema","typescript","zod"],"created_at":"2024-10-03T17:05:07.720Z","updated_at":"2025-10-07T02:45:09.214Z","avatar_url":"https://github.com/filp.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# next-better-api ⚡️🔵 [![npm version](https://badge.fury.io/js/next-better-api.svg)](https://badge.fury.io/js/next-better-api)\n\nOpinionated TypeScript-first helpers for building better [NextJS](https://nextjs.org/) APIs, powered by [Zod](https://github.com/colinhacks/zod).\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./logo.svg\"\u003e\n\u003c/p\u003e\n\n## At a glance:\n\n- 🙅‍♀️ Hands-off Typescript type inference based on your Zod validation schemas for query params, request body, and your API response\n- ✨ Type inference helpers to use with `react-query`, `fetch`, and other client-side utilities\n- 🔌 Minimal and composable \u0026mdash; bring your own request context, use existing middleware, etc\n- ☁ No additional dependencies (besides `zod` and `next` as `peerDependencies`, of course)\n\n```ts\nimport { z } from 'zod';\nimport { endpoint, asHandler } from 'next-better-api';\n\nconst getUser = endpoint(\n  {\n    method: 'get',\n    querySchema: z.object({\n      id: z.string(),\n    }),\n    responseSchema: z.object({\n      user: z.object({\n        id: z.string(),\n        name: z.string(),\n        email: z.string(),\n        active: z.boolean(),\n      }),\n    }),\n  },\n  async ({ query }) =\u003e {\n    const user = await getUser(query.id);\n\n    return {\n      status: 200,\n      body: {\n        user,\n      },\n    };\n  }\n);\n\nexport default asHandler([getUser]);\n```\n\n## Installation:\n\n\u003e Skip to [API reference](./DOCS.md)\n\n`next-better-api` requires `zod` for schema validation. You can install both libraries with yarn or npm on your existing NextJS project:\n\n```shell\n$ yarn add zod next-better-api\n\n// OR\n\n$ npm i -S zod next-better-api\n```\n\nAnd import it from your API definitions:\n\n```ts\nimport { endpoint, asHandler } from 'next-better-api';\nimport { z } from 'zod'; // If you are defining schemas for your endpoints\n```\n\nNow simply define individual endpoints for each HTTP method in your existing API files,\nand export your endpoints as a single `NextApiHandler`:\n\n```ts\n// pages/api/users.ts\nconst getUsers = endpoint(\n  {\n    method: 'get',\n  },\n  async () =\u003e {\n    const users = await getUsersFromDb();\n\n    return {\n      status: 200,\n      body: {\n        users,\n      },\n    };\n  }\n);\n\nexport default asHandler([getUsers]);\n```\n\n## API Reference\n\nSee [DOCS.md](./DOCS.md)\n\nFor an example setup, [check out my starter template/example](https://github.com/filp/nextjs-app-starter).\n\n---\n\n## Stuff\n\nSee license information under [`LICENSE.md`](/LICENSE.md).\n\nContributions are super welcome - in the form of bug reports, suggestions, or better yet, pull requests!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilp%2Fnext-better-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffilp%2Fnext-better-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilp%2Fnext-better-api/lists"}