Skip to content
0

KatanaKit ships a Bun-native server adapter (katanakit-js/adapters/bun) built on Bun.serve with the modern routes API (Bun v1.2.3+). It's a drop-in alternative to the Express adapter for Bun projects — no Express, no middleware chain, just a typed route table.

Install ​

bash
bun add katanakit-js

Add bun-types to your tsconfig.json types for the Bun global:

json
{
  "compilerOptions": {
    "types": ["bun-types"]
  }
}

Quick start ​

bun run dev:bun boots the dummyjson demo server:

bash
bun run dev:bun
# Server running at http://localhost:3000
ts
import { defineApiConfig } from "katanakit-js";
import { dummyJsonApiConfig, useBunStart } from "katanakit-js/adapters/bun";

defineApiConfig(dummyJsonApiConfig);

const server = useBunStart(3000);
console.log(`Server running at ${server.url}`);

The route table ​

useBuildDummyJsonRoutes() returns a typed Bun.serve route table. Handlers are pure and return Response — they reuse the core useFetch with the Safe Result pattern.

ts
import { useBuildDummyJsonRoutes } from "katanakit-js/adapters/bun";

Bun.serve({
  routes: useBuildDummyJsonRoutes(),
  fetch: () => new Response("Not Found", { status: 404 }),
});
RouteHandler
GET /api/statusstatic JSON
GET /api/productsuseDummyJsonProducts
GET /api/products/:iduseDummyJsonProductById
GET /api/products/search?q=useDummyJsonProductSearch
GET /api/products/categoriesuseDummyJsonProductCategories
GET /api/products/category/:categoryuseDummyJsonProductsByCategory
GET /api/users, GET /api/users/:idusers
GET /api/posts, GET /api/posts/:idposts
GET /api/quotes, GET /api/quotes/randomquotes
GET /api/seedoffline seed data
GET /api/*404 catch-all

Direct handlers ​

You can use the handlers anywhere a Response is expected — no Bun router required:

ts
import { defineApiConfig } from "katanakit-js";
import { dummyJsonApiConfig, useDummyJsonProducts } from "katanakit-js/adapters/bun";

defineApiConfig(dummyJsonApiConfig);
const response = await useDummyJsonProducts(); // Response with the product list

Seed data ​

ts
import { useGetDummyJsonSeed } from "katanakit-js/adapters/bun";

const seed = useGetDummyJsonSeed();
seed.products; // [{ id, title, description, category, price, rating, stock, brand }]
seed.users;    // [{ id, firstName, lastName, username, email, age, role }]

Server facade ​

useBunCreate is a singleton — subsequent calls return the same server:

ts
import { useBunCreate, useBunGetServer, useBunStop } from "katanakit-js/adapters/bun";

useBunCreate({ port: 3000, hostname: "localhost" });
useBunGetServer()?.url; // URL
await useBunStop();

Released under the MIT License.