{"id":14529683,"url":"https://github.com/richardsolomou/next-safe-route","last_synced_at":"2025-09-02T00:32:19.788Z","repository":{"id":243574092,"uuid":"812532999","full_name":"richardsolomou/next-safe-route","owner":"richardsolomou","description":"Type-safe and validated Route Handlers for Next.js","archived":true,"fork":false,"pushed_at":"2025-04-04T20:48:53.000Z","size":219,"stargazers_count":37,"open_issues_count":7,"forks_count":8,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-17T17:43:30.960Z","etag":null,"topics":["api","handler","next","nextjs","route","typesafe","typescript","zod"],"latest_commit_sha":null,"homepage":"https://npm.im/next-safe-route","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/richardsolomou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yaml","license":"LICENSE","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},"funding":{"github":"richardsolomou","ko_fi":"richardsolomou"}},"created_at":"2024-06-09T06:58:38.000Z","updated_at":"2025-05-16T09:32:25.000Z","dependencies_parsed_at":"2024-08-26T13:44:17.225Z","dependency_job_id":"7e5653b5-4308-42de-bb7c-cf33ae025cd6","html_url":"https://github.com/richardsolomou/next-safe-route","commit_stats":null,"previous_names":["richardsolomou/next-safe-route"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/richardsolomou/next-safe-route","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardsolomou%2Fnext-safe-route","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardsolomou%2Fnext-safe-route/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardsolomou%2Fnext-safe-route/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardsolomou%2Fnext-safe-route/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/richardsolomou","download_url":"https://codeload.github.com/richardsolomou/next-safe-route/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardsolomou%2Fnext-safe-route/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273213715,"owners_count":25065058,"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","handler","next","nextjs","route","typesafe","typescript","zod"],"created_at":"2024-09-05T00:01:01.680Z","updated_at":"2025-09-02T00:32:19.430Z","avatar_url":"https://github.com/richardsolomou.png","language":"TypeScript","funding_links":["https://github.com/sponsors/richardsolomou","https://ko-fi.com/richardsolomou"],"categories":["**1. Libraries**"],"sub_categories":["Others"],"readme":"\u003ch1 align=\"center\"\u003enext-safe-route\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/next-safe-route\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/next-safe-route?style=for-the-badge\u0026logo=npm\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/richardsolomou/next-safe-route/actions/workflows/test.yaml\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/richardsolomou/next-safe-route/test.yaml?style=for-the-badge\u0026logo=vitest\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/richardsolomou/next-safe-route/blob/main/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/next-safe-route?style=for-the-badge\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n`next-safe-route` is a utility library for Next.js that provides type-safety and schema validation for [Route Handlers](https://nextjs.org/docs/app/building-your-application/routing/route-handlers)/API Routes.\n\n## Features\n\n- **✅ Schema Validation:** Automatically validate request parameters, query strings, and body content with built-in error handling.\n- **🧷 Type-Safe:** Work with full TypeScript type safety for parameters, query strings, and body content.\n- **😌 Easy to Use:** Simple and intuitive API that makes defining route handlers a breeze.\n- **🔗 Extensible:** Compatible with any validation library supported by [TypeSchema](https://typeschema.com).\n- **🧪 Fully Tested:** Extensive test suite to ensure everything works reliably.\n\n## Installation\n\n```sh\nnpm install next-safe-route\n```\n\nThe library natively works with [zod](https://zod.dev) for schema validation, but you can use any other validation library that is supported by [TypeSchema](https://typeschema.com), as long as you install its respective adapter.\n\n## Usage\n\n```ts\n// app/api/hello/route.ts\nimport { createSafeRoute } from 'next-safe-route';\nimport { z } from 'zod';\n\nconst paramsSchema = z.object({\n  id: z.string(),\n});\n\nconst querySchema = z.object({\n  search: z.string().optional(),\n});\n\nconst bodySchema = z.object({\n  field: z.string(),\n});\n\nexport const GET = createSafeRoute()\n  .params(paramsSchema)\n  .query(querySchema)\n  .body(bodySchema)\n  .handler((request, context) =\u003e {\n    const { id } = context.params;\n    const { search } = context.query;\n    const { field } = context.body;\n\n    return Response.json({ id, search, field }), { status: 200 };\n  });\n```\n\nTo define a route handler in Next.js:\n\n1. Import `createSafeRoute` and your validation library (e.g., `zod`).\n2. Define validation schemas for params, query, and body as needed.\n3. Use `createSafeRoute()` to create a route handler, chaining `params`, `query`, and `body` methods.\n4. Implement your handler function, accessing validated and type-safe params, query, and body through `context`.\n\n## Tests\n\nTests are written using [Vitest](https://vitest.dev). To run the tests, use the following command:\n\n```sh\npnpm test\n```\n\n## Contributing\n\nContributions are welcome! For major changes, please open an issue first to discuss what you would like to change.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichardsolomou%2Fnext-safe-route","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frichardsolomou%2Fnext-safe-route","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichardsolomou%2Fnext-safe-route/lists"}