Skip to content

File-Based Routing

VentureKit automatically discovers API routes from your file system. No manual route registration is needed.

Routes live in your routesDir (typically src/routes/). Each file maps to an API endpoint based on its directory path and filename:

src/routes/<path>/<method>.ts → <METHOD> /<path>
FileRoute
src/routes/health/get.tsGET /health
src/routes/tasks/get.tsGET /tasks
src/routes/tasks/post.tsPOST /tasks
src/routes/tasks/[id]/get.tsGET /tasks/{id}
src/routes/tasks/[id]/put.tsPUT /tasks/{id}
src/routes/tasks/[id]/delete.tsDELETE /tasks/{id}
src/routes/admin/users/get.tsGET /admin/users

The filename determines the HTTP method:

FilenameMethod
get.tsGET
post.tsPOST
put.tsPUT
patch.tsPATCH
delete.tsDELETE

Use square brackets for path parameters:

src/routes/tasks/[id]/get.ts → GET /tasks/{id}
src/routes/users/[userId]/posts/[postId]/get.ts → GET /users/{userId}/posts/{postId}

Dynamic segments are converted to API Gateway path parameters ({id}, {userId}, etc.) and are available in ctx.rawEvent.pathParameters.

Every route file must export a main function created with handler():

src/routes/tasks/get.ts
import { handler } from '@venturekit/runtime';
export const main = handler(async (_body, ctx, logger) => {
logger.info('Listing tasks');
return [{ id: '1', title: 'Learn VentureKit' }];
});

Use the CLI to generate route files:

Terminal window
# Generate GET /tasks
vk g route tasks
# Generate POST /tasks with scopes
vk g route tasks -m post --scopes tasks.write
# Generate DELETE /tasks/{id}
vk g route tasks/[id] -m delete --scopes tasks.write

Set the routes directory in your vk.config.ts:

export default defineVenture({
// ...
routesDir: 'src/routes',
});

The path is relative to your project root.