Skip to main content

Standard Schema Support

BurgerAPI is not locked to Zod. Any schema library that follows the Standard Schema contract works through the same schema.ts convention, with no extra setup and no new dependency.

Libraries that implement Standard Schema include Valibot, ArkType, and Zod v4 itself.

Example with a Standard Schema library​

api/products/schema.ts
import { object, string, number } from "valibot"; // or any ~standard library

export const POST = {
body: object({
name: string(),
price: number(),
}),
};
api/products/route.ts
import { defineRoute } from "burger-api";
import { POST as PostSchema } from "./schema";

export const POST = defineRoute(PostSchema, (ctx) => {
const { name, price } = ctx.validated.body;
return Response.json({ name, price });
});

How detection works​

When a route is prepared, BurgerAPI picks the right connector for each schema:

  1. Zod is recognized first (it is the default provider).
  2. Any other library that exposes the Standard Schema contract (~standard.validate) is used automatically.
  3. If a schema is neither Zod nor a Standard Schema, BurgerAPI reports the error when the app starts.

Both Zod and a Standard Schema library can be used in the same app, even on different routes.

Rules​

  • The Standard Schema validator must be synchronous for request validation. An async validator causes an error at startup.
  • A declared body schema gates the media type: a non-JSON content type gets 415 Unsupported Media Type before validation runs. ctx.validated.body is non-optional when the schema declares body. See Body Validation for the empty-body and missing-Content-Type rules.
  • Zod remains the recommended default because it is what BurgerAPI documents and the examples use.