Skip to content

Bun Server

Typed routing, server setup, and response helpers for Bun HTTP servers. The package is intended for Bun applications that want typed route definitions, predictable response helpers, and simple Bun.serve() integration without adopting a larger framework.

Categories

  • RoutingdefineRoute creates typed method route definitions, defineHtmlRoute registers Bun HTML imports, and compileRoutes converts route collections into Bun routes.
  • ServercreateServer wraps Bun.serve() with defined routes by default, native Bun routes when requested, and default error handling.
  • ResponseHttpResponse adds a Bun file() factory to the shared @almighty-shogun/http-core class, whose methods create responses for JSON, HTML, text, image, no-content, redirect, and common status responses such as not found and method not allowed.
  • Types — route, handler, and server option type helpers for Bun request handlers.
  • Errors — the HTML route failures raised while compiling a route collection.

Dependencies

  • Bun runtime APIs — required for Bun.serve(), BunRequest, Server, Bun.file(), and HTML imports.
  • @almighty-shogun/http-core — a direct dependency providing the HTTP vocabulary, the query helpers, the error classes, and the response class.
  • @almighty-shogun/utils — a direct dependency, used for shared utility types only and never at runtime.

This package is Bun-specific and does not run on Node.js or in the browser.

Quick example

ts
import { createServer, defineRoute } from '@almighty-shogun/bun-server';

const routes = {
    health: defineRoute('/health', 'GET', (_, response) => {
        return response.json({ ok: true });
    })
};

createServer({ port: 3000, routes });

Continue with installation or jump to a category from the sidebar.

All packages are released under the MIT License.