{"_id":"@damienmonchaty/blitzjs","name":"@damienmonchaty/blitzjs","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@damienmonchaty/blitzjs","version":"1.0.0","description":"Ultra-fast HTTP framework with Elysia-like API built on uWebSockets.js","main":"dist/index.js","types":"dist/index.d.ts","publishConfig":{"access":"public"},"scripts":{"build":"tsc","prepublishOnly":"npm run build","publish:dry":"npm publish --dry-run","publish:public":"npm publish --access=public"},"keywords":["http","framework","fast","web","server","api","typescript","uwebsockets","elysia","performance"],"author":{"name":"Formation"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/formation/blitzjs.git"},"homepage":"https://github.com/formation/blitzjs#readme","bugs":{"url":"https://github.com/formation/blitzjs/issues"},"engines":{"node":">=16.0.0"},"peerDependencies":{"uWebSockets.js":">=20.52.0"},"dependencies":{"uWebSockets.js":"github:uNetworking/uWebSockets.js#v20.52.0"},"devDependencies":{"@types/node":"^22.15.30","ts-node":"^10.9.2","typescript":"^5.8.3"},"_id":"@damienmonchaty/blitzjs@1.0.0","_nodeVersion":"20.11.0","_npmVersion":"10.2.4","dist":{"integrity":"sha512-tzP9GlZ78Ascavcv2wbcTnr72Og3Gf6zI3BprMQ5mG9cF6yvCUZVcKrpgOvDqDFg8PJwV1Z+4SbuB66siHfdUQ==","shasum":"d50b1dab0535d67a21f77cf42b74d90b49f7280c","tarball":"https://registry.npmjs.org/@damienmonchaty/blitzjs/-/blitzjs-1.0.0.tgz","fileCount":11,"unpackedSize":69516,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIE1XAbcCo1edZgvW2dSQbIRPmIzryzX3AWGVQ2DRFgalAiBeAdfAms7S6UVqtbLPlrOjUuiLm3BOqMpoogxwA8hFIA=="}]},"_npmUser":{"name":"damienmonchaty","email":"damienmonchaty@hotmail.fr","actor":{"name":"damienmonchaty","email":"damienmonchaty@hotmail.fr","type":"user"}},"directories":{},"maintainers":[{"name":"damienmonchaty","email":"damienmonchaty@hotmail.fr"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/blitzjs_1.0.0_1751824272644_0.5786705345702119"},"_hasShrinkwrap":false}},"time":{"created":"2025-07-06T17:51:12.536Z","1.0.0":"2025-07-06T17:51:12.842Z","modified":"2025-07-06T17:51:13.187Z"},"maintainers":[{"name":"damienmonchaty","email":"damienmonchaty@hotmail.fr"}],"description":"Ultra-fast HTTP framework with Elysia-like API built on uWebSockets.js","homepage":"https://github.com/formation/blitzjs#readme","keywords":["http","framework","fast","web","server","api","typescript","uwebsockets","elysia","performance"],"repository":{"type":"git","url":"git+https://github.com/formation/blitzjs.git"},"author":{"name":"Formation"},"bugs":{"url":"https://github.com/formation/blitzjs/issues"},"license":"MIT","readme":"# BlitzJS ⚡\r\n\r\nUltra-fast HTTP framework with Elysia-like API built on uWebSockets.js\r\n\r\n## Features\r\n\r\n- ⚡ **Lightning Fast** - Built on uWebSockets.js, one of the fastest HTTP servers\r\n- 🎯 **Elysia-like API** - Clean, chainable syntax inspired by Elysia\r\n- 🔧 **TypeScript First** - Full TypeScript support with excellent type inference  \r\n- 📦 **Zero Dependencies** - Only uWebSockets.js as peer dependency\r\n- 🚀 **Auto Response** - Automatic JSON/string response handling\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install blitzjs\r\n```\r\n\r\n## Quick Start\r\n\r\n```typescript\r\nimport { BlitzJS } from 'blitzjs';\r\n\r\nnew BlitzJS()\r\n  .get('/', 'Hello BlitzJS!')\r\n  .get('/json', { message: 'Auto JSON response!' })\r\n  .get('/user/:id', (ctx) => ({ \r\n    id: ctx.params.id, \r\n    name: `User ${ctx.params.id}` \r\n  }))\r\n  .listen(3000);\r\n```\r\n\r\n## API\r\n\r\n### Simple Responses\r\n\r\n```typescript\r\n// String response\r\n.get('/', 'Hello World!')\r\n\r\n// JSON response  \r\n.get('/data', { key: 'value' })\r\n\r\n// Function response\r\n.get('/time', () => new Date().toISOString())\r\n\r\n// Dynamic response\r\n.get('/user/:id', (ctx) => ({ id: ctx.params.id }))\r\n```\r\n\r\n### HTTP Methods\r\n\r\n```typescript\r\nnew BlitzJS()\r\n  .get('/users', () => getAllUsers())\r\n  .post('/users', (ctx) => createUser(ctx.body))\r\n  .put('/users/:id', (ctx) => updateUser(ctx.params.id))\r\n  .delete('/users/:id', (ctx) => deleteUser(ctx.params.id))\r\n  .listen(3000);\r\n```\r\n\r\n### Context\r\n\r\nRoute handlers receive a context object:\r\n\r\n```typescript\r\ninterface RouteContext {\r\n  req: HttpRequest;      // uWebSockets.js request\r\n  res: HttpResponse;     // uWebSockets.js response  \r\n  params: Record<string, string>;  // Route parameters\r\n  query: Record<string, string>;   // Query parameters\r\n  body?: any;           // Request body (if parsed)\r\n}\r\n```\r\n\r\n### Middleware\r\n\r\n```typescript\r\nimport { BlitzJS } from 'blitzjs';\r\n\r\nconst app = new BlitzJS()\r\n  .use(async (ctx, next) => {\r\n    console.log(`${ctx.req.getMethod()} ${ctx.req.getUrl()}`);\r\n    await next();\r\n  })\r\n  .get('/', 'Hello with middleware!')\r\n  .listen(3000);\r\n```\r\n\r\n### Factory Function\r\n\r\n```typescript\r\nimport { Blitz } from 'blitzjs';\r\n\r\n// Use the factory function for a more functional approach\r\nconst app = Blitz()\r\n  .get('/', 'Hello from factory!')\r\n  .listen(3000);\r\n```\r\n\r\n## Performance\r\n\r\nBlitzJS leverages uWebSockets.js and advanced optimizations to deliver exceptional performance:\r\n\r\n### 🔥 Ultra-Performance Features\r\n\r\n- **Template Pattern Handler Generation** - Eliminates closures, reuses optimized templates\r\n- **O(1) Static Route Lookup** - HashMap-based routing for static routes\r\n- **O(log n) Dynamic Route Lookup** - Optimized trie-based routing for dynamic routes\r\n- **Runtime Code Generation** - JIT-compiled handlers for maximum performance\r\n- **Pre-computed Headers** - Eliminates header computation overhead\r\n- **Ultra-Fast Router** - Compiled dispatch function for minimal overhead\r\n\r\n### 📊 Benchmark Results\r\n\r\nLatest performance validation with Template Pattern optimizations:\r\n\r\n| Route Type | Req/s | Latency P50 | Optimization |\r\n|------------|-------|-------------|--------------|\r\n| Static String | 66,005 | 13ms | Template + O(1) HashMap |\r\n| Static JSON | 60,370 | 15ms | Template + O(1) HashMap |\r\n| Dynamic Single Param | 55,806 | 14ms | Template + Optimized Regex |\r\n| Dynamic Multi Param | 48,547 | 16ms | Template + Complex Regex |\r\n\r\n*Tested with autocannon: 100 connections, 10 pipelining, 10s duration*\r\n\r\n### 🚀 Performance Optimizations\r\n\r\n- **Template Pattern**: Handler templates compiled once, reused without closures\r\n- **Static Route HashMap**: O(1) lookup for static routes\r\n- **Dynamic Route Trie**: O(log n) lookup with optimized regex patterns\r\n- **Pre-computed Responses**: Headers and common responses cached\r\n- **JIT Compilation**: Runtime code generation for optimal V8 optimization\r\n\r\n## Template Pattern Architecture\r\n\r\nBlitzJS uses the **Template Pattern** for handler generation, achieving maximum performance by eliminating closures and enabling optimal V8 optimization:\r\n\r\n### Traditional Closure-based Approach\r\n```typescript\r\n// ❌ Creates closures for each handler - less optimal\r\nconst createHandler = (response) => {\r\n  return (ctx) => {\r\n    ctx.res.end(response); // Closure captures response\r\n  };\r\n};\r\n```\r\n\r\n### BlitzJS Template Pattern Approach  \r\n```typescript\r\n// ✅ Reusable templates without closures - ultra-optimized\r\nconst stringTemplate = function(ctx, precomputedResponse, precomputedHeaders) {\r\n  ctx.res.writeHeader('content-type', 'text/plain; charset=utf-8');\r\n  ctx.res.end(precomputedResponse);\r\n};\r\n\r\n// All handlers use the same optimized template function\r\n```\r\n\r\n### Benefits\r\n\r\n- **Zero Closures** - Templates are reused, no closure overhead\r\n- **V8 Optimization** - Templates get heavily optimized by V8 JIT\r\n- **Memory Efficiency** - Single template function for all similar handlers\r\n- **Pre-computed Data** - Responses and headers computed at compile time\r\n- **Maximum Performance** - Benchmarks show ~69,000 req/s throughput\r\n\r\n## Examples\r\n\r\nSee the `example/` directory:\r\n\r\n- `blitz-style.ts` - Complete BlitzJS example with various features\r\n\r\n## License\r\n\r\nMIT\r\n\r\n---\r\n\r\n**BlitzJS** - When you need speed ⚡\r\n","readmeFilename":"README.md","_rev":"1-da206272786816aaace90e6db1dcf31e"}