DEV Community

Alex Spinov
Alex Spinov

Posted on

Hono Has a Free API: The Ultrafast Web Framework That Runs Everywhere

What is Hono?

Hono is an ultrafast web framework built on Web Standards. It runs on Cloudflare Workers, Deno, Bun, Node.js, AWS Lambda, and any JavaScript runtime — with the same code. At just 14KB, it's one of the smallest full-featured frameworks available.

Why Hono?

  • Free and open-source — MIT license
  • Runs everywhere — Cloudflare Workers, Deno, Bun, Node.js, Lambda, Vercel
  • 14KB — smaller than Express (200KB+), faster than Fastify
  • Web Standards — uses Fetch API, Request/Response, no proprietary APIs
  • TypeScript-first — full type safety for routes, middleware, and validation
  • Built-in middleware — CORS, JWT, Bearer Auth, Logger, ETag, and more

Quick Start

npm create hono@latest my-api
cd my-api && bun install
Enter fullscreen mode Exit fullscreen mode
import { Hono } from 'hono';

const app = new Hono();

app.get('/', (c) => c.text('Hello Hono!'));

app.get('/api/users', (c) => {
  return c.json([{ id: 1, name: 'Alex' }, { id: 2, name: 'Sam' }]);
});

app.post('/api/users', async (c) => {
  const body = await c.req.json();
  return c.json({ id: 3, ...body }, 201);
});

export default app;
Enter fullscreen mode Exit fullscreen mode

Type-Safe Routes with Zod

import { Hono } from 'hono';
import { zValidator } from '@hono/zod-validator';
import { z } from 'zod';

const app = new Hono();

const createUserSchema = z.object({
  name: z.string().min(2),
  email: z.string().email(),
  role: z.enum(['admin', 'user']).default('user')
});

app.post('/api/users',
  zValidator('json', createUserSchema),
  async (c) => {
    const user = c.req.valid('json'); // Fully typed!
    return c.json({ id: 1, ...user }, 201);
  }
);
Enter fullscreen mode Exit fullscreen mode

Middleware

import { cors } from 'hono/cors';
import { jwt } from 'hono/jwt';
import { logger } from 'hono/logger';
import { prettyJSON } from 'hono/pretty-json';

const app = new Hono();

// Apply middleware
app.use('*', logger());
app.use('*', prettyJSON());
app.use('/api/*', cors({ origin: 'https://myapp.com' }));
app.use('/api/admin/*', jwt({ secret: 'my-secret' }));

app.get('/api/admin/dashboard', (c) => {
  const payload = c.get('jwtPayload');
  return c.json({ user: payload.sub, role: payload.role });
});
Enter fullscreen mode Exit fullscreen mode

RPC Client (End-to-End Type Safety)

// server.ts
const routes = app
  .get('/api/users', (c) => c.json([{ id: 1, name: 'Alex' }]))
  .post('/api/users', zValidator('json', createUserSchema), (c) => {
    return c.json({ id: 2, ...c.req.valid('json') });
  });

export type AppType = typeof routes;

// client.ts — FULL type safety!
import { hc } from 'hono/client';
import type { AppType } from './server';

const client = hc<AppType>('http://localhost:3000');

// TypeScript knows the response shape!
const res = await client.api.users.$get();
const users = await res.json(); // Typed as {id: number, name: string}[]
Enter fullscreen mode Exit fullscreen mode

Deploy Anywhere

// Cloudflare Workers
export default app;

// Node.js
import { serve } from '@hono/node-server';
serve(app);

// Bun
export default { port: 3000, fetch: app.fetch };

// AWS Lambda
import { handle } from 'hono/aws-lambda';
export const handler = handle(app);

// Deno
Deno.serve(app.fetch);
Enter fullscreen mode Exit fullscreen mode

Hono vs Alternatives

Feature Hono Express Fastify tRPC
Size 14KB 200KB+ 100KB+ 50KB+
Multi-runtime Yes Node only Node only Node/Bun
Type safety Native Manual Plugin Native
RPC client Built-in None None Core feature
Edge support Native No No Adapter
Speed (req/s) 150K+ 15K 75K N/A

Real-World Impact

A team maintained separate API codebases for Cloudflare Workers (miniflare), AWS Lambda (Serverless), and a Node.js dev server. With Hono: one codebase, same routes, deployed to all three targets. Code maintenance effort dropped by 60%, and they could test locally on any runtime.


Building APIs that run anywhere? I help teams choose and implement the right web framework. Contact spinov001@gmail.com or explore my data tools on Apify.

Top comments (0)