Elysia is a fast and type-safe web framework for Bun. RivetKit integrates seamlessly with Elysia using the .mount()
method.
View Example on GitHub
Check out the complete example
Installation
Install Elysia alongside RivetKit:
npm install elysia
# or with bun
bun add elysia
Basic Setup
Create Your Registry
Set up your Rivet Actors:
// 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 Elysia
Mount RivetKit into your Elysia application:
// server.ts
import { registry } from "./registry";
import { Elysia } from "elysia";
const { client, handler } = registry.createServer();
// Setup Elysia app
const app = new Elysia()
// Mount RivetKit handler
.mount("/registry", handler)
// Add your API routes
.post("/increment/:name", async ({ params }) => {
const name = params.name;
const counter = client.counter.getOrCreate([name]);
const newCount = await counter.increment(1);
return `New Count: ${newCount}`;
})
.get("/count/:name", async ({ params }) => {
const name = params.name;
const counter = client.counter.getOrCreate([name]);
const count = await counter.getCount();
return { count };
})
.listen(8080);
console.log("Server running at http://localhost:8080");