Docs / Routes
Routes
File-based routing. The path of the file is the URL.
File-based routing. Each file in app/routes/ becomes a URL.
| File | URL |
|---|---|
app/routes/index.ts | / |
app/routes/health.ts | /health |
app/routes/posts/[id].ts | /posts/:id |
app/routes/posts/[id]/publish.ts | /posts/:id/publish |
app/routes/files/[...path].ts | /files/* (catch-all) |
One HTTP method per export:
// app/routes/posts/[id].ts
import { defineRoute } from '@hopak/core';
export const GET = defineRoute({
handler: async (ctx) => {
return { id: ctx.params.id };
},
});
export const POST = defineRoute({
handler: async (ctx) => {
const body = await ctx.body();
return { received: body };
},
});
A default export is treated as GET.