Quick start
Build and run a RiserBob server with your first route.
Your first server
Create an index.ts file:
index.ts
import { RiserBob } from "riser-bob";import { UsersModule } from "./modules/users/users.module"; async function bootstrap() { const bob = new RiserBob(); bob.spongGet("/", async (spongReq, spongRes) => { return spongRes.json({ message: "Welcome to Bikini Bottom! 🍍", }); }); new UsersModule().register(bob); bob.spongListen(4000, () => { console.log("🧽 RiserBob is running at http://localhost:4000 🍍"); });} bootstrap().catch((error: unknown) => { console.error("[RiserBob] Failed to start application:", error); process.exit(1);});Run it:
Terminal
bun run index.tsThen call it:
Terminal
curl http://localhost:4000/Output
{"message":"Welcome to Bikini Bottom! 🍍"}This is the default entry file generated by bun create riser-bob. If you install RiserBob using bun add riser-bob, you'll need to create this file yourself, because RiserBob doesn't lock you into a specific structure.
Add a route with a parameter
TypeScript
bob.spongGet('/users/:id', async (spongReq, spongRes) => { const { id } = spongReq.params const page = spongReq.query.get('page') return spongRes.json({ id, page })})Every Sponge method returns the app, so you can chain routes. Continue with Routing for the details.
Read a JSON body
TypeScript
bob.spongPost('/users', async (spongReq, spongRes) => { const body = await spongReq.json<{ name: string }>() return spongRes.SpongCreated({ created: body.name })})Terminal
curl -X POST http://localhost:4000/users \ -H "Content-Type: application/json" \ -d '{"name":"Zen"}'Without the Content-Type: application/json header the request is answered with 415. See Request for every body-related answer.