{"id":20535704,"url":"https://github.com/vlucas/next-api-builder","last_synced_at":"2025-10-06T20:52:12.319Z","repository":{"id":61196809,"uuid":"549201086","full_name":"vlucas/next-api-builder","owner":"vlucas","description":"Next.js API Builder with great defaults","archived":false,"fork":false,"pushed_at":"2023-04-10T14:23:34.000Z","size":509,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-07T04:20:35.472Z","etag":null,"topics":["api","api-builder","next","nextjs","rest-api","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/next-api-builder","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vlucas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-10T20:43:27.000Z","updated_at":"2022-10-18T13:27:39.000Z","dependencies_parsed_at":"2024-10-13T05:01:00.730Z","dependency_job_id":null,"html_url":"https://github.com/vlucas/next-api-builder","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"b2c7c45c18dd8428444a6f14385ae712a7f73cda"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/vlucas/next-api-builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vlucas%2Fnext-api-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vlucas%2Fnext-api-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vlucas%2Fnext-api-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vlucas%2Fnext-api-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vlucas","download_url":"https://codeload.github.com/vlucas/next-api-builder/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vlucas%2Fnext-api-builder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273203230,"owners_count":25063275,"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-09-01T02:00:09.058Z","response_time":120,"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","api-builder","next","nextjs","rest-api","typescript"],"created_at":"2024-11-16T00:33:36.164Z","updated_at":"2025-10-06T20:52:07.247Z","avatar_url":"https://github.com/vlucas.png","language":"TypeScript","readme":"# Next.js API Builder\n\nAn easy way to build API routes in Next.js with the right defaults.\n\nFeatures:\n\n- Fully typed with TypeScript\n- Built-in schema validation with [Zod](https://github.com/colinhacks/zod)\n- Automatic `400: Bad Request` response when a Zod schema is supplied and the input data fails validation\n- Automatic `OPTIONS` response based on defined HTTP methods\n- Automatic `HEAD` response based on your defined `GET` handler\n- Automatic `405: Method Not Found` response for requests to methods not handled\n\n## Installation\n\nInstall with NPM:\n\n```\nnpm i next-api-builder\n```\n\nOr with Yarn:\n\n```\nyarn add next-api-builder\n```\n\n## Usage\n\n```javascript\nimport { apiRoute } from 'next-api-builder';\nimport type { NextApiRequest, NextApiResponse } from 'next/types';\n\nexport default apiRoute()\n  .get(async (req: NextApiRequest, res: NextApiResponse) =\u003e {\n    return { foo: 'bar!' };\n  })\n  .post(async (req: NextApiRequest, res: NextApiResponse) =\u003e {\n    // Insert data into some DB...\n    return req.body || { id: 0, title: 'Sample record' };\n  });\n```\n\n## Using Zod.js for Runtime Validation\n\nNext API builder uses [Zod](https://github.com/colinhacks/zod) for runtime validation of a request body and/or query\nstring parameters.\n\nYou can use a second optional object literal parameter when defining routes to supply a Zod schema.\n\n- `validateBody` - Parse the body as an object (from JSON, etc.) and run validations on it\n- `validateQuery` - Parse the query string and run validations on it\n\n```javascript\nimport { apiRoute } from 'next-api-builder';\nimport type { NextApiRequest, NextApiResponse } from 'next/types';\n\nconst schema = z.object({\n  name: z.string(),\n  email: z.string().email(),\n});\n\ntype TSchema = z.infer\u003ctypeof schema\u003e;\n\nexport default apiRoute().post(\n  async (req: NextApiRequest, res: NextApiResponse, data: TSchema) =\u003e {\n    // Insert data into some DB...\n    return data || { id: 0, title: 'Sample record' };\n  },\n  { validateBody: schema }, // Use 'validateBody' or 'validateQuery' with a Zod schema object\n);\n```\n\nIf the incoming HTTP Request fails validation, a `400: Bad Request` will be returned to the user with the field level\nerrors and messages returned from Zod, formatted to JSON.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvlucas%2Fnext-api-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvlucas%2Fnext-api-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvlucas%2Fnext-api-builder/lists"}