Request Inspection Properties
ctx.method
- Type:
string - The HTTP method verb in uppercase (
'GET','POST','PUT','DELETE','PATCH', etc.).
typescript
app.use((ctx, next) => {
console.log(`Incoming method: ${ctx.method}`);
return next();
});ctx.url
- Type:
string - The complete request URL, including the query string (e.g.
'/search?term=volten&page=2').
ctx.path
- Type:
string - The normalized path component of the request URL without the query string (e.g.
'/search').
ctx.params
- Type:
Record<string, string> - An object containing dynamic route parameters captured by the router (e.g.
/users/:idor wildcards/*).
typescript
app.get("/users/:id", (ctx) => {
const id = ctx.params.id;
return ctx.json({ id });
});
app.get("/static/*", (ctx) => {
const filePath = ctx.params["*"];
return ctx.send(`Static path: ${filePath}`);
});ctx.query
- Type:
Record<string, string | string[]> - Lazy-parsed query parameters from the request URL. Volten decodes percent-encoded characters and plus signs, and groups duplicate keys into arrays:
typescript
// GET /products?category=electronics&tag=deals&tag=sale
app.get("/products", (ctx) => {
const category = ctx.query.category; // 'electronics'
const tags = ctx.query.tag; // ['deals', 'sale']
return ctx.json({ category, tags });
});ctx.headers
- Type:
Record<string, string | string[] | undefined> - A dictionary of all incoming HTTP request headers with lowercase keys.
typescript
app.get("/headers", (ctx) => {
const userAgent = ctx.headers["user-agent"];
const authHeader = ctx.headers["authorization"];
return ctx.json({ userAgent, authHeader });
});ctx.ip
- Type:
string - The client IP address. Volten inspects proxy headers in the following priority order:
X-Forwarded-For(first IP in comma-separated list)CF-Connecting-IP(Cloudflare)- Direct socket address (
req.socket.remoteAddressin Node.js)
typescript
app.get("/client-ip", (ctx) => {
return ctx.json({ ip: ctx.ip });
});ctx.host and ctx.hostname
- Type:
string ctx.host: Host header value (including port if present, e.g.'localhost:3000').ctx.hostname: Host header value without port (e.g.'localhost'). RespectsX-Forwarded-Host.
ctx.isMultipart
- Type:
boolean - Returns
trueif the incoming request'sContent-Typeheader includesmultipart/form-data.
ctx.runtime
- Type:
'node' | 'edge' - Identifies whether the application is running in a Node.js environment or an Edge/Web standard worker runtime.
ctx.env and ctx.executionCtx
- Type:
unknown - In Edge environments (e.g. Cloudflare Workers), these provide access to environment bindings (KV namespaces, D1 databases, secrets) and execution context (
waitUntil).