Hono is an ultra-fast web framework that works on any runtime. RivetKit integrates seamlessly with Hono through the serve()
method.
View Example on GitHub
Check out the complete example
Installation
Install Hono alongside RivetKit:
Basic Setup
Create Your Registry
Set up your Rivet Actor:
// registry.ts
import { actor, setup } from "@rivetkit/actor";
export const counter = actor({
state: { count: 0 },
actions: {
increment: (c, amount: number = 1) => {
c.state.count += amount;
c.broadcast("countChanged", c.state.count);
return c.state.count;
},
getCount: (c) => c.state.count,
},
});
export const registry = setup({
use: { counter },
});
Integrate with Hono
Use RivetKit’s serve()
method with your Hono app:
// server.ts
import { registry } from "./registry";
import { Hono } from "hono";
// Start RivetKit
const { client, serve } = registry.createServer();
// Setup Hono app
const app = new Hono();
// Add your API routes
app.post("/increment/:name", async (c) => {
const name = c.req.param("name");
const body = await c.req.json().catch(() => ({}));
const amount = body.amount || 1;
try {
const counter = client.counter.getOrCreate([name]);
const newCount = await counter.increment(amount);
return c.json({ success: true, count: newCount });
} catch (error) {
return c.json({
success: false,
error: error.message
}, 500);
}
});
app.get("/count/:name", async (c) => {
const name = c.req.param("name");
try {
const counter = client.counter.getOrCreate([name]);
const count = await counter.getCount();
return c.json({ name, count });
} catch (error) {
return c.json({
success: false,
error: error.message
}, 500);
}
});
// Start server with RivetKit integration
serve(app);