{"_id":"@c-wiren/safe-router","_rev":"9-f175011a74b5b46ecf2b2c374f7a7fb2","name":"@c-wiren/safe-router","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"@c-wiren/safe-router","version":"0.1.0","keywords":["web","app","http","application","framework","router","cloudflare","workers","safe","simple"],"author":{"url":"https://github.com/c-wiren","name":"Christian Wirén","email":"christian@wiren.cc"},"license":"MIT","_id":"@c-wiren/safe-router@0.1.0","maintainers":[{"name":"c-wiren","email":"christian@wiren.cc"}],"homepage":"https://github.com/c-wiren/safe-router#readme","bugs":{"url":"https://github.com/c-wiren/safe-router/issues"},"dist":{"shasum":"0462cd34c7d34897c27f8f82fc14b1ef2ef8390a","tarball":"https://registry.npmjs.org/@c-wiren/safe-router/-/safe-router-0.1.0.tgz","fileCount":23,"integrity":"sha512-SfV7b0WqywCUoKmscq93fZz3Xz4Eub2yA6u+5W2Bn1k9boRIx+9wSNkcrcmtNQKwrSJaAZ3V1Kxa30JfhEMgrw==","signatures":[{"sig":"MEUCIBCte5UtXXOtQ5c7Xzg/4iHjpqj1PPGUCPgdEgggBagfAiEA7WH+D6CQo5JDtXJ/dpyKgsr9pVO0W0gvIbf7tf2G1Uw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":36158},"main":"dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./client":{"types":"./dist/client/index.d.ts","import":"./dist/client/index.js"},"./package.json":"./package.json"},"gitHead":"15ad50728c279c2f0616c2e3b9bf0d693c59c1fa","scripts":{"test":"vitest","build":"tsc","clean":"rimraf coverage dist","coverage":"vitest run --coverage"},"_npmUser":{"name":"c-wiren","email":"christian@wiren.cc"},"repository":{"url":"git+https://github.com/c-wiren/safe-router.git","type":"git"},"_npmVersion":"9.5.1","description":"Simple and safe web framework for Cloudflare Workers with built in validation using Zod","directories":{},"_nodeVersion":"18.16.0","publishConfig":{"registry":"https://registry.npmjs.org"},"_hasShrinkwrap":false,"devDependencies":{"rimraf":"^5.0.1","vitest":"^0.32.2","typescript":"^5.1.3","@edge-runtime/vm":"^3.0.3","@vitest/coverage-v8":"^0.32.2"},"peerDependencies":{"zod":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/safe-router_0.1.0_1707764850995_0.6505703956968203","host":"s3://npm-registry-packages"}},"0.2.0":{"name":"@c-wiren/safe-router","version":"0.2.0","type":"module","description":"Simple and safe web framework for Cloudflare Workers with built in validation using Zod","main":"dist/index.js","scripts":{"build":"tsc","test":"vitest","coverage":"vitest run --coverage","clean":"rimraf coverage dist"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./client":{"types":"./dist/client/index.d.ts","import":"./dist/client/index.js"},"./package.json":"./package.json"},"keywords":["web","app","http","application","framework","router","cloudflare","workers","safe","simple"],"author":{"name":"Christian Wirén","email":"christian@wiren.cc","url":"https://github.com/c-wiren"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/c-wiren/safe-router.git"},"publishConfig":{"registry":"https://registry.npmjs.org"},"devDependencies":{"@edge-runtime/vm":"^3.0.3","@vitest/coverage-v8":"^0.32.2","rimraf":"^5.0.1","typescript":"^5.1.3","vitest":"^0.32.2"},"peerDependencies":{"zod":"^3.0.0"},"types":"./dist/index.d.ts","gitHead":"4567a8fff33a612a856107276e977fd40d210e95","bugs":{"url":"https://github.com/c-wiren/safe-router/issues"},"homepage":"https://github.com/c-wiren/safe-router#readme","_id":"@c-wiren/safe-router@0.2.0","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"integrity":"sha512-ruubj83nkmr3HIhninSBy8x4U7bFpGPVWmb+B/oO9wOQsPbhsL+EwjFxqmxCmII2/WlcRiEEUw4JSbycZHqpNQ==","shasum":"5e6fd2f1d54025a574fc69c935ba712e8152e527","tarball":"https://registry.npmjs.org/@c-wiren/safe-router/-/safe-router-0.2.0.tgz","fileCount":27,"unpackedSize":42317,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIEXN6K//vJm7WFqN8ixo/S8ES/dxob6IkMXS5rE+Le9uAiBQ/epVvI0+txWZPKSJOygrMJqrNcrsfaRMgTXmW6omKg=="}]},"_npmUser":{"name":"c-wiren","email":"christian@wiren.cc"},"directories":{},"maintainers":[{"name":"c-wiren","email":"christian@wiren.cc"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/safe-router_0.2.0_1753097768046_0.9415247321885976"},"_hasShrinkwrap":false}},"time":{"created":"2024-02-12T19:07:30.867Z","modified":"2025-07-21T11:36:08.390Z","1.0.0":"2023-06-23T12:53:54.138Z","1.0.1":"2023-06-24T18:24:55.340Z","1.1.0":"2024-02-06T21:12:10.263Z","1.1.1":"2024-02-06T21:29:43.016Z","0.1.0":"2024-02-12T19:07:31.180Z","0.2.0":"2025-07-21T11:36:08.219Z"},"bugs":{"url":"https://github.com/c-wiren/safe-router/issues"},"author":{"name":"Christian Wirén","email":"christian@wiren.cc","url":"https://github.com/c-wiren"},"license":"MIT","homepage":"https://github.com/c-wiren/safe-router#readme","keywords":["web","app","http","application","framework","router","cloudflare","workers","safe","simple"],"repository":{"type":"git","url":"git+https://github.com/c-wiren/safe-router.git"},"description":"Simple and safe web framework for Cloudflare Workers with built in validation using Zod","maintainers":[{"name":"c-wiren","email":"christian@wiren.cc"}],"readme":"# safe-router\n\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/c-wiren/safe-router/ci.yml?branch=main)](https://github.com/c-wiren/safe-router/actions)\n[![License](https://img.shields.io/github/license/c-wiren/safe-router)](https://github.com/c-wiren/safe-router/blob/main/LICENSE)\n[![npm](https://img.shields.io/npm/v/@c-wiren/safe-router)](https://www.npmjs.com/package/@c-wiren/safe-router)\n\nsafe-router is a simple, safe, and fast web API framework. Create a safe API with minimal code. All needed types are created automatically.\n\n## About\n\nDeveloping safe APIs can be complicated. While it seems easy to get started with a REST API, validation of URL parameters, queries, and request body makes things difficult quickly. And the result is rarely particularly readable. \n\nsafe-router is an opinionated framework. All requests are done with POST. All parameters are sent in the request body, and are validated automatically using Zod. A handler receives an object and returns an object. Any other interactions with the raw request are done in separate extensions to keep things tidy. The result is minimal code with maximum safety and simplicity.\n\n## Installation\n```\nnpm install @c-wiren/safe-router zod\n```\n\n## Examples\n\nDefine a function:\n```typescript\nimport App from '@c-wiren/safe-router';\n\nconst app = new App();\n\napp.define('getUser', async c => {\n  return { id: 0 };\n});\n```\n\nAdd Zod input type; it will be validated automatically and appear at ```c.params```:\n```typescript\nimport App from '@c-wiren/safe-router';\nimport { z } from 'zod';\n\nconst app = new App();\n\napp.define('getUser', z.object({ id: z.number() }), async c => {\n  return { id: c.params.id };\n});\n```\n\nAdd an Environment type and access it at ```c.env```:\n```typescript\ntype Bindings = { SECRET: string; };\n\nconst app = new App<Bindings>();\n\napp.define('getSecret', async c => c.env.SECRET);\n```\n\nHandle errors easily:\n```typescript\napp.define('getUser', async c => {\n  const user = DB.getUser();\n  if (user) { return user; }\n  else { return c.ClientError('NotFound'); }\n});\n```\n\nOr even easier:\n```typescript\napp.define('getUser', async c => {\n  const user = DB.getUser();\n  return user ?? c.ClientError('NotFound');\n});\n```\n\nUse typed error messages:\n```typescript\ntype ErrorMessage = 'NotFound' | 'Unknown';\n\nconst app = new App<Bindings, ErrorMessage>();\n```\n\nTo keep things nice and tidy, handlers don't have access to the raw request. To access things such as headers, use an extension. The returned object is added to ```c.<EXTENSION_NAME>```.\n```typescript\nconst withAuth = app.createExtension('auth', c => {\n  const header = c.request.headers.get('Authentication');\n  const user = getUserFromToken(header); // Placeholder function\n  return { user };\n});\n\napp.define('getUser', [withAuth], async c => {\n  return c.auth.user;\n});\n```\n","readmeFilename":"README.md"}