Skip to main content

Complete Project Example

A full BurgerAPI project follows the 1.0 layout. App-level files live in src/, each with one job:

src/
├── index.ts # Burger instance + burger.serve(port)
├── plugins.ts # register plugins
├── providers.ts # declare shared services
├── hooks.ts # global hooks (onRequest, beforeRoute, ...)
├── openapi.config.ts # OpenAPI metadata and docs config
└── api/ # routes
└── products/
├── route.ts # export async function GET(ctx: BurgerContext)
├── schema.ts # per-method validation schemas
├── hooks.ts # route hooks
├── openapi.ts # per-method OpenAPI metadata
└── config.ts # route options (auth, cache, timeout, ...)
src/index.ts
import { Burger } from "burger-api";

const burger = new Burger({ apiDir: "./src/api" });

burger.serve(4000);
src/plugins.ts
import type { PluginRegistrar } from "burger-api";

export default (burger: PluginRegistrar) => {
// burger.usePlugin(myPlugin);
};
src/providers.ts
import type { ProviderRegistrar } from "burger-api";

export default (burger: ProviderRegistrar) => {
// burger.provide("db", db);
};
src/hooks.ts
import type { BurgerContext } from "burger-api";

export const onRequest = [
async (ctx: BurgerContext) => {
// runs for every request
},
];

Build-time concerns (dirs, prefixes, debug) live in burger.build.ts and are used by the CLI only. Runtime options belong in new Burger({...}), src/plugins.ts, and route config.ts.

Use burger-api create my-app to scaffold this structure. Run the dev server with bun run dev; build and start with burger-api build and burger-api start. For step-by-step builds, see the Blog API and Todo API tutorials.