Skip to content

Overview

The query is a component of the request target.
E.g. baz=qux is the query component in https://example.com/foo/bar?baz=qux or /foo/bar?baz=qux.

The query is primarily used to encode data in GET requests and redirects. Check out "Query parameters" for more details on how to extract structured data out of the raw query.

Injection

Inject RequestHead to access the raw query via its target field:

src/query/routes.rs
use pavex::http::StatusCode;
use pavex::request::RequestHead;

pub fn handler(head: &RequestHead) -> StatusCode {
    if let Some(raw_query /* (1)! */) = head.target.query() {
        println!("The raw query is `{raw_query}`");
    } else {
        println!("There is no query string");
    }
    // [...]
}
  1. The query string is an optional component of the request target. It may not be there!