ReferenceAPI
Edit this page

API

Bun Runtime APIs Used by react-bun-ssr

Map the Bun-native APIs used by the framework to the public framework surface and official Bun documentation.

bunapiruntimereference

This page maps the Bun-native APIs used by react-bun-ssr to the framework surface you interact with in routes, config, deployment, and generated docs.

How to use this page

Use this page when you need to answer one of these questions quickly:

  • Which Bun runtime primitive powers a framework feature?
  • Is this Bun API something application code should care about directly, or is it internal?
  • Where is the framework intentionally wrapping Bun instead of exposing Bun objects directly?

Each section calls out:

  • the Bun API involved
  • where the framework uses it
  • whether it is Framework-facing or Internal-only
  • official Bun documentation
  • the most relevant framework docs entrypoint

HTTP server runtime

Bun API: Bun.serve()

Framework usage: react-bun-ssr starts its production and development HTTP server on top of Bun’s native server runtime. The public entrypoints that matter here are createServer and startHttpServer.

Classification: Framework-facing

When you deploy the framework, you are still deploying a Bun server. The framework provides the request handler and document/render pipeline, but the actual HTTP runtime is Bun.

Official Bun docs:

Framework docs:

Cookies

Bun APIs: Bun.Cookie, Bun.CookieMap

Framework usage: the framework parses cookies into ctx.cookies, but it does not currently expose Bun’s CookieMap directly. Public route contexts expose a normalized Map<string, string>.

Classification: Framework-facing

This distinction matters:

  • Bun’s native HTTP server can expose cookie helpers like req.cookies backed by CookieMap
  • react-bun-ssr currently exposes cookies as a framework abstraction over cookie parsing
  • application route code should treat ctx.cookies as Map<string, string>, not as Bun.CookieMap
import type { LoaderContext } from "react-bun-ssr/route";

export async function loader({ cookies }: LoaderContext) {
  const session = cookies.get("session");
  return { authenticated: Boolean(session) };
}

Do not document or expect a framework cookies() helper here, because it does not exist in this project.

Official Bun docs:

Framework docs:

Markdown rendering

Bun API: Bun.markdown

Framework usage: markdown route compilation and docs-page HTML generation rely on Bun’s markdown support. The framework then adds its own wrapper/module generation and heading ID handling on top of that.

Classification: Framework-facing

This is why .md routes can stay first-class without bringing in a separate markdown/MDX compiler stack.

Official Bun docs:

Framework docs:

File I/O and static assets

Bun APIs: Bun.file, Bun.write

Framework usage: the framework uses Bun-native file APIs for generated docs artifacts, runtime file reads, build output, and static asset handling paths.

Classification: Framework-facing

These APIs show up in two ways:

  • directly in internal scripts and generators
  • indirectly in the production/runtime behavior you see through static asset serving and build output

Official Bun docs:

Framework docs:

Build and bundling

Bun API: Bun.build

Framework usage: route modules and client entries are bundled through Bun’s build pipeline.

Classification: Internal-only

This is core to framework implementation, but it is not a day-to-day route API. Most users only need to care about it when debugging build output, deployment differences, or bundle behavior.

Official Bun docs:

Framework docs:

Routing internals

Bun API: Bun.FileSystemRouter

Framework usage: the framework uses Bun’s file-system router internally as the authoritative matcher after projecting framework route conventions into a Bun-compatible route tree.

Classification: Internal-only

Application route authors do not interact with Bun.FileSystemRouter directly, but it matters for understanding why routing behavior stays Bun-native even though the framework supports conventions Bun does not model directly on its own.

Official Bun docs:

Framework docs:

Bun utilities adopted in the framework

The framework also leans on Bun runtime utilities where they make the code smaller, safer, or more deterministic.

Classification: mixed, but mostly Internal-only

  • Bun.escapeHTML() for HTML-safe rendering paths and markdown heading IDs
  • Bun.inspect() for better runtime diagnostics
  • Bun.pathToFileURL() and Bun.fileURLToPath() for module loading and file URL conversion
  • Bun.Glob for scanning docs and runtime/build inputs
  • Bun.CryptoHasher for stable hashes
  • Bun.randomUUIDv7() for temp directory naming
  • Bun.spawnSync() for POSIX helper commands used by internal tooling

Official Bun docs:

Framework docs:

Internal-only appendix

Bun APIUsed inWhyPublic or internalBun docs
Bun.buildroute/client bundlingBuild route modules and browser assetsInternal-onlyBundler
Bun.FileSystemRouterruntime route matchingMatch projected framework routes with Bun-native routingInternal-onlyFile System Router
Bun.Globdocs/runtime scanningFind route files, docs files, and source inputs efficientlyInternal-onlyGlob
Bun.CryptoHasherhashing helpersProduce deterministic short hashesInternal-onlyBun APIs
Bun.randomUUIDv7()temp directoriesGenerate stable, unique temp-path suffixesInternal-onlyBun APIs
Bun.spawnSync()internal POSIX opsRun small helper commands without adding Node process wrappersInternal-onlyBun APIs