Platforms
Bun
Running mion APIs on Bun runtime for maximum performance.
Bun support is experimental. It works for most use cases, but some edge cases may not be fully tested.
Installing the Adapter
bun add @mionjs/platform-bun @mionjs/router
Starting the Server
import {startBunServer} from '@mionjs/platform-bun';
import './bun-routes.ts';
const server = await startBunServer({port: 3000});
console.log(`Server running at http://localhost:${server.port}`);
import {createMionRouter, Routes} from '@mionjs/router';
const mion = createMionRouter();
const routes = {
sayHello: mion.route((ctx, name: string): string => {
return `Hello ${name}!`;
}),
} satisfies Routes;
// the server entry only imports this file
export const myApi = mion.initRoutes(routes);
export type MyApi = typeof myApi;
Adapter Options
Pass options such as maxBodySize to startBunServer, and set router options like basePath once in createMionRouter. Each route has its own body limit, and a body over it is refused with a 413. Bun's own read limit is set to the largest route limit at startup, which stops an oversized upload mid-flight.
import {startBunServer} from '@mionjs/platform-bun';
import './bun-routes.ts';
await startBunServer({port: 3000});
Bun's native HTTP server is extremely fast and handles high throughput workloads well.