Request Parameters
Unified access to route parameters, query strings, and request body data.
One Access Point
The req["all"] field merges parameters from all sources into a single convenient hash. No more checking multiple places for your data.
1 Parameter Sources
Parameters can come from three places in an HTTP request:
Route Params
Embedded in the URL path
/users/:id/posts/:post_id
Query Params
URL query string
?page=1&limit=20
Body Params
Request body (JSON/form)
{"name": "Alice"}
2
The Unified all Field
// Request: PUT /items/42?status=active
// Body: {"status": "urgent", "quantity": "5"}
fn update_item(req: Any) -> Any {
// Unified access to all parameters
let all = req["all"];
// ID from route params
print("ID:", all["id"]); // "42"
// Status appears in both query and body
// Body value takes precedence!
print("Status:", all["status"]); // "urgent" (from JSON body)
// Quantity from body only
print("Quantity:", all["quantity"]); // "5"
return {"status": 200, "body": "Updated"};
}
3 Priority Order
When the same parameter exists in multiple sources, values are merged with this priority (highest wins):
4 Individual Sources Still Work
You can still access individual parameter sources separately:
5 Complete Example: Search API
// GET /api/search?q=rust&page=2
// or POST /api/search with body {"q": "rust", "filters": "recent"}
fn search(req: Any) -> Any {
let all = req["all"];
// Unified params allow flexible API design
let query = all["q"] or "";
let page = all["page"] or "1";
let limit = all["limit"] or "20";
// Use unified params for filtering
let filters = {
"query": query,
"page": page,
"limit": limit,
"category": all["category"], // Optional
"sort": all["sort"] or "relevance",
"min_price": all["min_price"], // Optional
"max_price": all["max_price"] // Optional
};
// Execute search
let results = execute_search(filters);
return {
"status": 200,
"body": json_stringify({
"results": results,
"page": page,
"limit": limit
})
};
}
API Reference
| Field | Type | Description |
|---|---|---|
| req["method"] | String | HTTP method (GET, POST, etc.) |
| req["path"] | String | Request path |
| req["params"] | Hash | Route parameters only |
| req["query"] | Hash | Query string parameters only |
| req["all"] | Hash | Unified parameters (route + query + body) |
| req["json"] | Any/Null | Parsed JSON body |
| req["form"] | Hash/Null | Parsed form data |
| req["headers"] | Hash | Request headers |
| req["body"] | String | Raw request body |
Benefits
Flexibility
Clients can send parameters via URL, query string, or body - your handler doesn't care where they come from.
Simplicity
Single access point for all parameters. No more checking multiple places.
Backward Compatible
Individual sources (req["params"], req["query"]) still work exactly as before.
Intuitive Priority
Body params naturally override URL params. No manual merging required.