Skip to main content

@sgrnext/api

Sweetin' your API

DocumentationPlugins
src/app/api/books/route.ts
import { compileSchema } from '@sgrnext/api-parse';
import { z } from "zod";
import { handlers } from '@/server/handlers';

export POST = handlers.create(async (env) => {
const { title, price } = await env.parse(SCHEMA, ZOD_SCHEMA)
const { id } = await env.pool.execute('...', [ title, price ]);

return { id };
});

const SCHEMA = compileSchema({ title: 'body', price: 'body' });
const ZOD_SCHEMA = z.object({ title: z.string(), price: z.number() });