Route signatures
The registration signature is app.get(path, handler, schema?, middleware[]?). The same order applies to post, put, patch, delete, head, and options. app.all() registers a method fallback; app.add(method, path, ...) accepts an explicit method.
Complete routing example
index.ts
import { Volt } from 'voltts';
const app = new Volt();
app.get('/status', () => ({ ok: true }));
app.get('/users/:id', (c) => ({ id: c.params.id }));
app.get('/posts/:postId/comments/:commentId', (c) => ({
postId: c.params.postId,
commentId: c.params.commentId,
}));
app.get('/files/*filepath', (c) => c.text(c.params.filepath));
app.post('/items', (c) => c.json({ item: c.body }, 201));
app.delete('/items/:id', () => new Response(null, { status: 204 }));
if (globalThis._importMeta_.main) app.listen(3000);
export default app;Try parameters and wildcards
bash
bun run index.ts
curl http://localhost:3000/users/42
curl http://localhost:3000/posts/1/comments/2
curl http://localhost:3000/files/reports/annual.csvThe parameter handler returns ID 42 as a string. A wildcard captures the remaining path. Do not map a wildcard directly to an unchecked filesystem path.
HEAD and OPTIONS
HEAD requests use the registered route and omit the response body. OPTIONS discovery reports registered methods. For browser preflight requests, register CORS middleware before routes. Unknown routes produce a 404 response; do not assume every unsupported method produces 405.