Ultra-fast HTTP server
npm install zap-rs> Ultra-fast HTTP server for Node.js - 10-100x faster than Express.js
š Blazing Performance ⢠┠SIMD-Optimized ⢠š„ Zero-Allocation Routing ⢠šÆ Full TypeScript Support
Built with Rust and NAPI-RS, Zap delivers unmatched performance while maintaining a clean, Bun-inspired API that developers love.
- š 10-100x faster than Express.js (powered by Rust)
- ā” SIMD-optimized HTTP parsing with zero-copy operations
- š„ Zero-allocation routing with 9ns static route lookup
- šÆ Full TypeScript support with type-safe route parameters
- š§āāļø Auto-serialization for JSON responses
- š§ Powerful middleware system compatible with existing patterns
- š Built-in static file serving with compression and security
- š Modern async/await throughout
- š Express.js compatibility layer for easy migration
- šØ Clean, Bun-inspired API that's intuitive and powerful
``bash`
npm install @zapjs/coreor
yarn add @zapjs/coreor
pnpm add @zapjs/core
`typescript
import { Zap } from '@zapjs/core';
const server = new Zap();
await server.port(3000);
await server.get('/', () => 'Hello, World! š');
await server.get_json('/api/status', () => ({
status: 'ok',
performance: '10-100x faster than Express.js'
}));
console.log('š Server running on http://localhost:3000');
await server.listen();
`
`typescript
import { createServer } from '@zapjs/core';
createServer()
.port(3000)
.hostname('0.0.0.0')
.cors()
.logging()
.get('/', () => 'Hello, World! š')
.get_json('/api/users/:id', (req) => ({
id: req.params.id,
name: 'John Doe',
email: user${req.params.id}@example.com`
}))
.static_files('/assets', './public')
.health_check('/health')
.listen();
`typescript
import { serve } from '@zapjs/core';
serve({
port: 3000,
fetch: (req) => {
if (req.path === '/') return 'Hello, World!';
if (req.path === '/api/time') return JSON.stringify({ time: Date.now() });
return 'Not Found';
}
});
`
`typescript
const server = new Zap();
// Basic configuration
await server.port(3000); // Set port
await server.hostname('0.0.0.0'); // Set hostname
await server.max_request_body_size(50 1024 1024); // 50MB limit
// Middleware
await server.cors(); // Enable CORS
await server.logging(); // Enable request logging
`
`typescript
// Simple text responses
await server.get('/', () => 'Hello World');
await server.post('/echo', async (req) => req.body);
// JSON responses (auto-serialized)
await server.get_json('/api/users', () => [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' }
]);
await server.post_json('/api/users', (req) => {
const userData = JSON.parse(req.body);
return { id: 123, ...userData };
});
// All HTTP methods supported
await server.put('/api/users/:id', handler);
await server.delete('/api/users/:id', handler);
`
`typescript
// Type-safe parameters
await server.get_json('/users/:id/posts/:postId', (req) => {
const { id, postId } = req.params; // TypeScript knows these are strings
return { userId: id, postId };
});
// Query parameters
await server.get_json('/search', (req) => {
const query = req.query.q || '';
const limit = parseInt(req.query.limit || '10');
return { query, limit, results: [] };
});
// Headers and cookies
await server.get_json('/profile', (req) => ({
userAgent: req.headers['user-agent'],
sessionId: req.cookies.session,
authorization: req.headers.authorization
}));
`
`typescript
// Basic static files
await server.static_files('/assets', './public');
// Advanced options
await server.static_files('/downloads', './files', {
directory_listing: true,
cache_control: 'public, max-age=31536000',
headers: {
'X-Served-By': 'Zap'
},
compress: true
});
`
`typescript
// Built-in health check
await server.health_check('/health');
// Built-in metrics endpoint
await server.metrics('/metrics');
// Custom monitoring
await server.get_json('/api/status', () => ({
status: 'healthy',
uptime: process.uptime(),
memory: process.memoryUsage(),
version: '1.0.0'
}));
`
`typescript
import { TypedRequest, RouteParams } from '@zapjs/core';
// Automatic parameter type inference
type UserRouteParams = RouteParams<'/users/:id/posts/:postId'>;
// Result: { id: string; postId: string }
await server.get_json('/users/:id/posts/:postId', (req: TypedRequest<'/users/:id/posts/:postId'>) => {
const { id, postId } = req.params; // Fully typed!
return { userId: parseInt(id), postId: parseInt(postId) };
});
`
`typescript
import { Request, StaticFileOptions } from '@zapjs/core';
interface User {
id: number;
name: string;
email: string;
}
await server.post_json('/api/users', (req: Request): User => {
const userData = JSON.parse(req.body);
return {
id: Math.random() * 1000,
name: userData.name,
email: userData.email
};
});
`
Drop-in replacement for many Express.js apps:
`typescript
import { express } from '@zapjs/core';
const app = express();
app.get('/', (req, res) => {
res.send('Hello World');
});
app.get('/api/users', (req, res) => {
res.json([{ id: 1, name: 'Alice' }]);
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});
`
Zap delivers 10-100x better performance than Express.js:
| Framework | Requests/sec | Latency (p99) | Memory Usage |
|-----------|--------------|---------------|--------------|
| Express.js | 15,000 | 45ms | 50MB |
| Zap | 150,000 | 0.8ms | 12MB |
Benchmarks run on M1 MacBook Pro with 1KB JSON responses
- š¦ Rust Core: Zero-allocation HTTP parsing and routing
- ā” SIMD Instructions: Vectorized string operations
- šÆ Smart Routing: Radix tree with 9ns static lookups
- š„ Zero-Copy: Minimal memory allocations
- āļø Optimized Compilation: Release builds with LTO
`typescript${ctx.method} ${ctx.path}
await server.use_middleware({
async call(ctx) {
console.log();`
return { continue: true };
}
});
`typescript`
await server.get_async('/api/error', async (req) => {
try {
// Your logic here
return 'Success';
} catch (error) {
return JSON.stringify({
error: error.message,
status: 500
});
}
});
`typescript`
await server.post_json('/api/upload', (req) => {
const contentType = req.headers['content-type'];
if (!contentType?.startsWith('multipart/form-data')) {
return { error: 'Expected multipart/form-data' };
}
return {
message: 'File uploaded successfully',
size: req.body.length,
contentType
};
});
Check out the examples directory for more comprehensive demos:
- basic.js - Simple server setup
- typescript.ts - Full TypeScript example
- fluent.js - Fluent API patterns
- rest-api.js - Complete REST API
`bashClone the repository
git clone https://github.com/zapjs/zap-rs.git
cd zap-rs/zap-napi
šļø Architecture
`
āāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāā
ā TypeScript ā ā NAPI-RS ā ā Rust Core ā
ā Beautiful āāāāāŗā Zero-Copy āāāāāŗā Ultra-Fast ā
ā Developer ā ā Bindings ā ā HTTP Engine ā
ā Experience ā ā ā ā ā
āāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāā
``- TypeScript Layer: Clean, type-safe API
- NAPI-RS Bridge: Zero-copy data transfer
- Rust Core: SIMD-optimized HTTP parsing & routing
MIT Ā© Zap Team
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
If Zap makes your life easier, please ā star us on GitHub!
---
Made with ā¤ļø and ā” by the Zap team