{"_id":"@adi-family/http-native","_rev":"4-1b34e51778ef099b8f39a0669bf33037","name":"@adi-family/http-native","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.0":{"name":"@adi-family/http-native","version":"1.0.0","keywords":["http","native","node","adapter","type-safe","validation","typescript"],"author":{"name":"ADI Family"},"license":"MIT","_id":"@adi-family/http-native@1.0.0","maintainers":[{"name":"mgorunuch","email":"mgorunuch.igor@gmail.com"}],"homepage":"https://github.com/adi-family/http#readme","bugs":{"url":"https://github.com/adi-family/http/issues"},"dist":{"shasum":"e9a8956adf7ba1da409ebc9178e16dcc9b0da956","tarball":"https://registry.npmjs.org/@adi-family/http-native/-/http-native-1.0.0.tgz","fileCount":6,"integrity":"sha512-4EfuyPZiIG5nIXI5pYj2RqRZMVPNMDgPeOYunSSM81T8QDbdQmdst4uO3mUuNkxovkGcxdBd4UZ+fthoFEzkSA==","signatures":[{"sig":"MEYCIQDZJfCJm2pUw1N9gEa6SFjMoAWTmoOtM9JjNzBxu16NngIhAJz8xH6zpDQDGEo/UA/zNppxxpfN/+J6q2mld1PaHelo","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":27447},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"}},"gitHead":"f47297207e8b0a091f6b00875f9d54bac0b21915","scripts":{"build":"tsc","typecheck":"tsc --noEmit","prepublishOnly":"bun run build"},"_npmUser":{"name":"mgorunuch","email":"mgorunuch.igor@gmail.com"},"repository":{"url":"git+https://github.com/adi-family/http.git","type":"git","directory":"packages/http-native"},"_npmVersion":"10.9.2","description":"Native Node.js HTTP adapter for @adi-family/http","directories":{},"_nodeVersion":"23.10.0","dependencies":{"@adi-family/http":"workspace:*"},"_hasShrinkwrap":false,"devDependencies":{"zod":"^3.22.4","typescript":"^5.3.0","@types/node":"^20.10.0"},"peerDependencies":{"zod":"^3.22.0"},"_npmOperationalInternal":{"tmp":"tmp/http-native_1.0.0_1762107143765_0.5580032807153439","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@adi-family/http-native","version":"1.0.1","keywords":["http","native","node","adapter","type-safe","validation","typescript"],"author":{"name":"ADI Family"},"license":"MIT","_id":"@adi-family/http-native@1.0.1","maintainers":[{"name":"mgorunuch","email":"mgorunuch.igor@gmail.com"}],"homepage":"https://github.com/adi-family/http#readme","bugs":{"url":"https://github.com/adi-family/http/issues"},"dist":{"shasum":"8b753681d791015aa5378b6a0d379dc8ef089783","tarball":"https://registry.npmjs.org/@adi-family/http-native/-/http-native-1.0.1.tgz","fileCount":6,"integrity":"sha512-KrM/bTlh8tC/Ug4eOqyE7JlxLUDa3riuACaJZCY61+Qgi0VohJ3e/GH120RBmIMn7q4kGZ+OerkoWu2y5PtnWA==","signatures":[{"sig":"MEQCIBWuWQan1V9zdbA4N8V4XPKVlorMnPvi3aJbxAIoY6Z9AiBOENeqPYvRN9m/Z9qg+hD/Pb6n2BxysX0nXyVMBOXdNw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":27442},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"}},"gitHead":"f47297207e8b0a091f6b00875f9d54bac0b21915","scripts":{"build":"tsc","typecheck":"tsc --noEmit","prepublishOnly":"bun run build"},"_npmUser":{"name":"mgorunuch","email":"mgorunuch.igor@gmail.com"},"repository":{"url":"git+https://github.com/adi-family/http.git","type":"git","directory":"packages/http-native"},"_npmVersion":"10.9.2","description":"Native Node.js HTTP adapter for @adi-family/http","directories":{},"_nodeVersion":"23.10.0","dependencies":{"@adi-family/http":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"zod":"^3.22.4","typescript":"^5.3.0","@types/node":"^20.10.0"},"peerDependencies":{"zod":"^3.22.0"},"_npmOperationalInternal":{"tmp":"tmp/http-native_1.0.1_1762108857886_0.9135277985593517","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@adi-family/http-native","version":"1.0.2","keywords":["http","native","node","adapter","type-safe","validation","typescript"],"author":{"name":"ADI Family"},"license":"MIT","_id":"@adi-family/http-native@1.0.2","maintainers":[{"name":"mgorunuch","email":"mgorunuch.igor@gmail.com"}],"homepage":"https://github.com/adi-family/http#readme","bugs":{"url":"https://github.com/adi-family/http/issues"},"dist":{"shasum":"7918d0e47cd23dd646ed11dfe91d0b3bd82eaa11","tarball":"https://registry.npmjs.org/@adi-family/http-native/-/http-native-1.0.2.tgz","fileCount":6,"integrity":"sha512-iuQ85ERF0KqnFwxSi53uyxZeCzJZ4l+fPGex5oXRDHvRb2Lt32so0N/i65e90nLu7XQqe5SNGSOrXYIEt/fZzQ==","signatures":[{"sig":"MEQCIAD2HpsFrzWnvGpEentLLEuZRiiBj7QNF22++4nJBMJvAiBljtmwcSwVH0SR+w4erQxZ2ORu81n8Xs3kAoA0BwxNOg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":27462},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"}},"gitHead":"b83b53691026e1e7c3782c2a2dcfa4d350f190cf","scripts":{"build":"tsc","typecheck":"tsc --noEmit","prepublishOnly":"bun run build"},"_npmUser":{"name":"mgorunuch","email":"mgorunuch.igor@gmail.com"},"repository":{"url":"git+https://github.com/adi-family/http.git","type":"git","directory":"packages/http-native"},"_npmVersion":"10.9.2","description":"Native Node.js HTTP adapter for @adi-family/http","directories":{},"_nodeVersion":"23.10.0","dependencies":{"@adi-family/http":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"zod":"^3.22.4","typescript":"^5.3.0","@types/node":"^20.10.0"},"peerDependencies":{"zod":"^3.22.0"},"_npmOperationalInternal":{"tmp":"tmp/http-native_1.0.2_1762649684066_0.537724572138423","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@adi-family/http-native","version":"1.0.3","type":"module","description":"Native Node.js HTTP adapter for @adi-family/http","main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/index.js","require":"./dist/index.js","types":"./dist/index.d.ts"}},"scripts":{"build":"tsc","typecheck":"tsc --noEmit","prepublishOnly":"bun run build"},"keywords":["http","native","node","adapter","type-safe","validation","typescript"],"author":{"name":"ADI Family"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/adi-family/http.git","directory":"packages/http-native"},"bugs":{"url":"https://github.com/adi-family/http/issues"},"homepage":"https://github.com/adi-family/http#readme","dependencies":{"@adi-family/http":"^1.0.0"},"peerDependencies":{"zod":"^3.22.0"},"devDependencies":{"@types/node":"^20.10.0","typescript":"^5.3.0","zod":"^3.22.4"},"_id":"@adi-family/http-native@1.0.3","gitHead":"b83b53691026e1e7c3782c2a2dcfa4d350f190cf","_nodeVersion":"23.10.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-DH5C2CgWBJkR/MNg//DjhXyeeZvyCWufBp7WyVGuOrMfCbcRJo16G4fvO/eZuzLVA9hYIljcBkiGANd79A6pRw==","shasum":"2213764f49be379589a640afbeaab57cf58d93d3","tarball":"https://registry.npmjs.org/@adi-family/http-native/-/http-native-1.0.3.tgz","fileCount":6,"unpackedSize":27462,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCmSfOe4REnNWdpggtE5wPQPmm0P24oUJPGG5FlhsGdWAIhAOb//xsFhw6Ld+JijQyi/OBp1Ufp4TUH4LAZyQQVr2qC"}]},"_npmUser":{"name":"mgorunuch","email":"mgorunuch.igor@gmail.com"},"directories":{},"maintainers":[{"name":"mgorunuch","email":"mgorunuch.igor@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/http-native_1.0.3_1762650309933_0.9095024654867869"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-02T18:12:23.677Z","modified":"2025-11-09T01:05:10.420Z","1.0.0":"2025-11-02T18:12:23.966Z","1.0.1":"2025-11-02T18:40:58.083Z","1.0.2":"2025-11-09T00:54:44.263Z","1.0.3":"2025-11-09T01:05:10.174Z"},"bugs":{"url":"https://github.com/adi-family/http/issues"},"author":{"name":"ADI Family"},"license":"MIT","homepage":"https://github.com/adi-family/http#readme","keywords":["http","native","node","adapter","type-safe","validation","typescript"],"repository":{"type":"git","url":"git+https://github.com/adi-family/http.git","directory":"packages/http-native"},"description":"Native Node.js HTTP adapter for @adi-family/http","maintainers":[{"name":"mgorunuch","email":"mgorunuch.igor@gmail.com"}],"readme":"# @adi-family/http-native\n\nNative Node.js HTTP adapter for [@adi-family/http](https://www.npmjs.com/package/@adi-family/http) - converts type-safe handlers into native Node.js HTTP server handlers without any framework dependencies.\n\n## Installation\n\n```bash\nnpm install @adi-family/http @adi-family/http-native zod\n# or\nbun add @adi-family/http @adi-family/http-native zod\n```\n\n## Quick Start\n\n```typescript\nimport { serveNative } from '@adi-family/http-native'\nimport { getUserHandler, createUserHandler } from './handlers'\n\nconst server = serveNative(\n  [getUserHandler, createUserHandler],\n  {\n    port: 3000,\n    hostname: '0.0.0.0',\n    onListen: (port, hostname) => {\n      console.log(`Server running on http://${hostname}:${port}`)\n    }\n  }\n)\n```\n\n## Features\n\n- **Zero Dependencies** - Uses only Node.js built-in `http` and `https` modules\n- **Automatic Routing** - Maps handlers to routes automatically\n- **Built-in Validation** - Validates query and body with Zod\n- **Error Handling** - Handles validation errors automatically\n- **Type Safety** - Full TypeScript support\n- **HTTPS Support** - Easy HTTPS server setup\n\n## Usage Examples\n\n### Basic HTTP Server\n\n```typescript\nimport { serveNative } from '@adi-family/http-native'\nimport { handler, route } from '@adi-family/http'\nimport { z } from 'zod'\n\nconst getUserHandler = handler(\n  {\n    method: 'GET',\n    route: route.pattern('/api/users/:id', z.object({ id: z.string() })),\n    response: {\n      schema: z.object({\n        id: z.string(),\n        name: z.string()\n      })\n    }\n  },\n  async (ctx) => {\n    const user = await db.users.findById(ctx.params.id)\n    return user\n  }\n)\n\nconst server = serveNative([getUserHandler], {\n  port: 3000\n})\n```\n\n### HTTPS Server\n\n```typescript\nimport { serveNative } from '@adi-family/http-native'\nimport { readFileSync } from 'fs'\n\nconst server = serveNative([getUserHandler], {\n  port: 443,\n  hostname: '0.0.0.0',\n  https: {\n    key: readFileSync('./private-key.pem'),\n    cert: readFileSync('./certificate.pem')\n  },\n  onListen: (port, hostname) => {\n    console.log(`HTTPS server running on https://${hostname}:${port}`)\n  }\n})\n```\n\n### Custom Server Setup\n\nIf you need more control over the server, use `createHandler` instead:\n\n```typescript\nimport http from 'http'\nimport { createHandler } from '@adi-family/http-native'\nimport { getUserHandler, createUserHandler } from './handlers'\n\nconst requestHandler = createHandler([\n  getUserHandler,\n  createUserHandler\n])\n\nconst server = http.createServer(requestHandler)\n\n// Add custom middleware or configuration\nserver.on('error', (error) => {\n  console.error('Server error:', error)\n})\n\nserver.listen(3000, '0.0.0.0', () => {\n  console.log('Server is running')\n})\n```\n\n### With Query Parameters\n\n```typescript\nimport { handler, route } from '@adi-family/http'\nimport { z } from 'zod'\n\nconst listUsersHandler = handler(\n  {\n    method: 'GET',\n    route: route.static('/api/users'),\n    query: {\n      schema: z.object({\n        page: z.number().optional(),\n        limit: z.number().optional(),\n        search: z.string().optional()\n      })\n    },\n    response: {\n      schema: z.array(z.object({\n        id: z.string(),\n        name: z.string()\n      }))\n    }\n  },\n  async (ctx) => {\n    const { page = 1, limit = 10, search } = ctx.query\n    const users = await db.users.findAll({ page, limit, search })\n    return users\n  }\n)\n```\n\n### With Request Body\n\n```typescript\nconst createUserHandler = handler(\n  {\n    method: 'POST',\n    route: route.static('/api/users'),\n    body: {\n      schema: z.object({\n        name: z.string().min(1),\n        email: z.string().email(),\n        age: z.number().min(0).optional()\n      })\n    },\n    response: {\n      schema: z.object({\n        id: z.string(),\n        name: z.string(),\n        email: z.string()\n      })\n    }\n  },\n  async (ctx) => {\n    const user = await db.users.create(ctx.body)\n    return user\n  }\n)\n```\n\n## API Reference\n\n### `serveNative(handlers, options)`\n\nCreates and starts a native Node.js HTTP or HTTPS server.\n\n**Parameters:**\n- `handlers: Handler[]` - Array of handlers to serve\n- `options: NativeServerOptions` - Server configuration options\n\n**Options:**\n- `port?: number` - Port to listen on (default: 3000)\n- `hostname?: string` - Hostname to bind to (default: 'localhost')\n- `https?: https.ServerOptions` - HTTPS options (creates HTTPS server if provided)\n- `onListen?: (port, hostname) => void` - Callback when server starts\n\n**Returns:** `http.Server | https.Server`\n\n### `createHandler(handlers)`\n\nCreates a request handler without starting a server. Useful for testing or custom server setup.\n\n**Parameters:**\n- `handlers: Handler[]` - Array of handlers\n\n**Returns:** `(req: IncomingMessage, res: ServerResponse) => Promise<void>`\n\n## Routing\n\nThe adapter automatically:\n- Matches request method (GET, POST, PUT, PATCH, DELETE)\n- Parses URL parameters from Express-style patterns (`:id`)\n- Parses query parameters and converts numbers automatically\n- Parses JSON request bodies\n- Returns 404 for unmatched routes\n\n## Error Handling\n\nThe adapter automatically handles:\n- **Zod validation errors** - Returns 400 with error details\n- **Not found** - Returns 404 for unmatched routes\n- **Server errors** - Returns 500 for handler exceptions\n- **Invalid JSON** - Returns 400 for malformed request bodies\n\n## Performance\n\nThis adapter uses only Node.js built-in modules, making it:\n- **Lightweight** - No heavy framework dependencies\n- **Fast** - Direct HTTP handling without middleware overhead\n- **Simple** - Easy to understand and debug\n\n## Documentation\n\nFor complete documentation and examples, visit:\nhttps://github.com/adi-family/http\n\n## License\n\nMIT - See LICENSE file for details\n\nCopyright (c) 2025 ADI Family (https://github.com/adi-family)\n","readmeFilename":"README.md"}