Ultra-fast HTTP framework with simple, intuitive API built on uWebSockets.js
β οΈ Development Status: BlitzJS is currently in active development. The API may change before the stable release. Not recommended for production use yet.
- β‘ Lightning Fast - Built on uWebSockets.js, one of the fastest HTTP servers
- π― Simple & Clean API - Intuitive, chainable syntax for maximum productivity
- π§ TypeScript First - Full TypeScript support with excellent type inference
- π¦ Zero Dependencies - Only uWebSockets.js as peer dependency
- π Auto Response - Automatic JSON/string response handling
Note: BlitzJS is not yet published on npm. This is a development preview.
# When available on npm (coming soon)
npm install blitzjsFor now, you can clone and build locally:
git clone <repository-url>
cd BlitzJS
npm install
npm run buildimport { BlitzJS } from 'blitzjs';
new BlitzJS()
.get('/', 'Hello BlitzJS!')
.get('/json', { message: 'Auto JSON response!' })
.get('/user/:id', (ctx) => ({
id: ctx.params.id,
name: `User ${ctx.params.id}`
}))
.listen(3000);// String response
.get('/', 'Hello World!')
// JSON response
.get('/data', { key: 'value' })
// Function response
.get('/time', () => new Date().toISOString())
// Dynamic response
.get('/user/:id', (ctx) => ({ id: ctx.params.id }))new BlitzJS()
.get('/users', () => getAllUsers())
.post('/users', (ctx) => createUser(ctx.body))
.put('/users/:id', (ctx) => updateUser(ctx.params.id))
.delete('/users/:id', (ctx) => deleteUser(ctx.params.id))
.listen(3000);Route handlers receive a context object:
interface RouteContext {
req: HttpRequest; // uWebSockets.js request
res: HttpResponse; // uWebSockets.js response
params: Record<string, string>; // Route parameters
query: Record<string, string>; // Query parameters
body?: any; // Request body (if parsed)
}import { BlitzJS } from 'blitzjs';
const app = new BlitzJS()
.use(async (ctx, next) => {
console.log(`${ctx.req.getMethod()} ${ctx.req.getUrl()}`);
await next();
})
.get('/', 'Hello with middleware!')
.listen(3000);import { Blitz } from 'blitzjs';
// Use the factory function for a more functional approach
const app = Blitz()
.get('/', 'Hello from factory!')
.listen(3000);BlitzJS leverages uWebSockets.js and advanced optimizations to deliver exceptional performance:
- Template Pattern Handler Generation - Eliminates closures, reuses optimized templates
- O(1) Static Route Lookup - HashMap-based routing for static routes
- O(log n) Dynamic Route Lookup - Optimized trie-based routing for dynamic routes
- Runtime Code Generation - JIT-compiled handlers for maximum performance
- Pre-computed Headers - Eliminates header computation overhead
- Ultra-Fast Router - Compiled dispatch function for minimal overhead
Note: These are preliminary benchmarks from development testing. Official benchmarks will be published with the stable release.
Latest performance validation with Template Pattern optimizations:
| Route Type | Req/s | Latency P50 | Optimization |
|---|---|---|---|
| Static String | 66,005 | 13ms | Template + O(1) HashMap |
| Static JSON | 60,370 | 15ms | Template + O(1) HashMap |
| Dynamic Single Param | 55,806 | 14ms | Template + Optimized Regex |
| Dynamic Multi Param | 48,547 | 16ms | Template + Complex Regex |
Tested with autocannon: 100 connections, 10 pipelining, 10s duration
- Template Pattern: Handler templates compiled once, reused without closures
- Static Route HashMap: O(1) lookup for static routes
- Dynamic Route Trie: O(log n) lookup with optimized regex patterns
- Pre-computed Responses: Headers and common responses cached
- JIT Compilation: Runtime code generation for optimal V8 optimization
BlitzJS uses the Template Pattern for handler generation, achieving maximum performance by eliminating closures and enabling optimal V8 optimization:
// β Creates closures for each handler - less optimal
const createHandler = (response) => {
return (ctx) => {
ctx.res.end(response); // Closure captures response
};
};// β
Reusable templates without closures - ultra-optimized
const stringTemplate = function(ctx, precomputedResponse, precomputedHeaders) {
ctx.res.writeHeader('content-type', 'text/plain; charset=utf-8');
ctx.res.end(precomputedResponse);
};
// All handlers use the same optimized template function- Zero Closures - Templates are reused, no closure overhead
- V8 Optimization - Templates get heavily optimized by V8 JIT
- Memory Efficiency - Single template function for all similar handlers
- Pre-computed Data - Responses and headers computed at compile time
- Maximum Performance - Benchmarks show ~69,000 req/s throughput
- Request body parsing (JSON, form-data, etc.)
- Query string parsing
- Cookie support
- Session management
- Static file serving
- Error handling middleware
- CORS support
- Rate limiting
- WebSocket support
- Plugin system
- Request validation
- Authentication helpers
- Database integrations
- OpenAPI/Swagger support
- Testing utilities
- Performance monitoring
- Clustering support
BlitzJS is in active development and we welcome contributions!
git clone <repository-url>
cd BlitzJS
npm install
npm run dev- π§ͺ Testing: Writing comprehensive test suites
- π Documentation: Improving examples and guides
- β‘ Performance: Benchmarking and optimization
- π§ Features: Implementing roadmap items
- π Bug Reports: Finding and reporting issues
See the example/ directory:
blitz-style.ts- Complete BlitzJS example with various features
MIT
BlitzJS - When you need speed β‘