Request & response
Handlers receive a Request and return a Response. The framework calls response.deliver (with optional CORS) after routing.
Request API
Section titled “Request API”| Function | Returns | Description |
|---|---|---|
query(req, key) |
String |
Query parameter value |
param(req, key) |
String |
Path param from :key segment (empty if no pattern) |
header(req, name) |
String |
Request header (case-insensitive lookup via runtime) |
body(req, max_len) |
String |
Read body up to max_len bytes (empty on failure) |
body_result(req, max_len) |
Result<String, int> |
Body read with error code |
context_value(req) |
String |
Middleware-parsed body stored on request |
with_context(req, ctx) |
Request |
Attach context (used by middleware) |
parse_json(req, max_len) |
Result<String, int> |
Read + validate JSON body |
import lib.requestimport lib.response
fn show(req: request.Request) -> response.Response { let q = request.query(req, "q"); let id = request.param(req, "id"); let auth = request.header(req, "Authorization"); return response.json("{\"q\":\"" + q + "\",\"id\":\"" + id + "\"}");}After use_json middleware, prefer context_value(req) for the parsed JSON string instead of re-reading the body.
Response API
Section titled “Response API”| Function | Status | Content-Type |
|---|---|---|
send(body) |
200 | inferred (plain) |
send(status, body) |
given | inferred (plain) |
send_typed(status, ct, body) |
given | explicit |
json(body) |
200 | application/json; charset=utf-8 |
json(status, body) |
given | application/json; charset=utf-8 |
send_status(status) |
given | empty body |
redirect(url) |
302 | Location header |
redirect(status, url) |
given | Location header |
Error helpers
Section titled “Error helpers”| Function | Status |
|---|---|
not_found(body) |
404 |
bad_request(body) |
400 |
payload_too_large(body) |
413 |
unauthorized(body) |
401 |
server_error(body) |
500 |
fn create_item(req: request.Request) -> response.Response { let body = request.body(req, 65536); if len(body) == 0 { return response.bad_request("{\"error\":\"empty body\"}"); } return response.json(201, "{\"ok\":true}");}Redirects
Section titled “Redirects”return response.redirect("/login"); // 302return response.redirect(301, "/canonical"); // permanentThe runtime sets the Location header via http_reply_cors.
Barrel re-exports
Section titled “Barrel re-exports”When using import vws from vow_web_server, request/response helpers are also on the barrel:
let id = vws.param(req, "id");return vws.json(201, "{\"ok\":true}");return vws.redirect("/home");Submodule imports (vow_web_server.request, vow_web_server.response) remain the typed option for handler signatures.
CORS on responses
Section titled “CORS on responses”use_cors(a, origin) wraps delivered responses with Access-Control-Allow-Origin. OPTIONS preflight returns 204 before middleware/route dispatch when CORS is enabled.