Hattip is a universal HTTP framework that runs the same code on Node.js, Deno, Bun, Cloudflare Workers, Vercel, Netlify, and AWS Lambda — no platform-specific code needed.
Core Concept
Hattip uses the Web Standard Request/Response API everywhere:
import { createRouter } from '@hattip/router';
const app = createRouter();
app.get('/', () => {
return new Response('Hello from Hattip!');
});
app.get('/api/users', async () => {
const users = await db.getUsers();
return new Response(JSON.stringify(users), {
headers: { 'Content-Type': 'application/json' }
});
});
app.post('/api/users', async (context) => {
const body = await context.request.json();
const user = await db.createUser(body);
return new Response(JSON.stringify(user), { status: 201 });
});
export default app;
Deploy Anywhere
Same code, different adapters:
// Node.js
import { createServer } from '@hattip/adapter-node';
createServer(app).listen(3000);
// Cloudflare Workers
import cloudflareAdapter from '@hattip/adapter-cloudflare-workers';
export default { fetch: cloudflareAdapter(app) };
// Deno
import { serve } from '@hattip/adapter-deno';
serve(app, { port: 3000 });
// Bun
import bunAdapter from '@hattip/adapter-bun';
export default bunAdapter(app);
Middleware
import { cookie } from '@hattip/cookie';
import { cors } from '@hattip/cors';
app.use(cookie());
app.use(cors({ origin: 'https://myapp.com' }));
app.use(async (context) => {
const start = Date.now();
const response = await context.next();
console.log(`${context.method} ${context.url} - ${Date.now() - start}ms`);
return response;
});
Why This Matters
- Write once, deploy anywhere: Same handler on 7+ platforms
- Web standards: Uses fetch API Request/Response natively
- Zero lock-in: Switch platforms by changing one import
- Tiny footprint: ~5KB core, tree-shakeable middleware
Need custom universal API tools or multi-platform deployment? I build developer tools. Check out my web scraping actors on Apify or reach out at spinov001@gmail.com for custom solutions.
Top comments (0)