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.
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-facingorInternal-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.cookiesbacked byCookieMap react-bun-ssrcurrently exposescookiesas a framework abstraction over cookie parsing- application route code should treat
ctx.cookiesasMap<string, string>, not asBun.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 IDsBun.inspect()for better runtime diagnosticsBun.pathToFileURL()andBun.fileURLToPath()for module loading and file URL conversionBun.Globfor scanning docs and runtime/build inputsBun.CryptoHasherfor stable hashesBun.randomUUIDv7()for temp directory namingBun.spawnSync()for POSIX helper commands used by internal tooling
Official Bun docs:
Framework docs:
Internal-only appendix
| Bun API | Used in | Why | Public or internal | Bun docs |
|---|---|---|---|---|
Bun.build | route/client bundling | Build route modules and browser assets | Internal-only | Bundler |
Bun.FileSystemRouter | runtime route matching | Match projected framework routes with Bun-native routing | Internal-only | File System Router |
Bun.Glob | docs/runtime scanning | Find route files, docs files, and source inputs efficiently | Internal-only | Glob |
Bun.CryptoHasher | hashing helpers | Produce deterministic short hashes | Internal-only | Bun APIs |
Bun.randomUUIDv7() | temp directories | Generate stable, unique temp-path suffixes | Internal-only | Bun APIs |
Bun.spawnSync() | internal POSIX ops | Run small helper commands without adding Node process wrappers | Internal-only | Bun APIs |