ESC
Type to search...
S
Soli Docs

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

controllers/items_controller.sl
# Request: PUT /items/42?status=active
# Body: {"status": "urgent", "quantity": "5"}

def update_item(req: 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"

    {"status": 200, "body": "Updated"}
end

3 Priority Order

When the same parameter exists in multiple sources, values are merged with this priority (highest wins):

3
Body params Highest priority - overrides everything
2
Query params Overrides route params
1
Route params Base priority

4 Individual Sources Still Work

You can still access individual parameter sources separately:

handlers.sl
def handler(req: Any)    # Route parameters only
    let id = req["params"]["id"];

    # Query parameters only
    let page = req["query"]["page"];

    # JSON body only
    let data = req["json"];

    # Form data only
    let form = req["form"];

    # Or unified access
    let all = req["all"];

    {"status": 200, "body": "OK"}
end

5 Complete Example: Search API

controllers/search_controller.sl
# GET /api/search?q=2
# orrust&page= POST /api/search with body {"q": "rust", "filters": "recent"}

def search(req: 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);

    {
        "status": 200,
        "body": json_stringify({
            "results": results,
            "page": page,
            "limit": limit
        })
    }
end

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.