Expand description
Extract data from the URL of incoming requests.
§Overview
When it comes to route information, there are two important extractors to be aware of:
PathParams: extract path parameters from the URL of incoming requestsMatchedPathPattern: extract the route template that matched for the incoming request
Check out their documentation for more details.
§Example: path parameters
use pavex::{get, request::path::PathParams};
// Define a route with a path parameter, `{home_id}`.
// The `PathParams` extractor deserializes the extracted path parameters into
// the type you specified—`Home` in this case.
#[get(path = "/home/{home_id}")]
pub fn get_home(params: &PathParams<Home>) -> String {
format!("The identifier for this home is: {}", params.0.home_id)
}
// The PathParams attribute macro derives the necessary (de)serialization traits.
#[PathParams]
pub struct Home {
// The name of the field must match the name of the path parameter
// used in the route definition.
home_id: u32
}Check out PathParams’ documentation for more details.
Modules§
- errors
- Errors that can happen when extracting path parameters.
Structs§
- Encoded
Param Value - A wrapper around a percent-encoded path parameter, obtained via
RawPathParams. - Matched
Path Pattern - The route template that matched for the incoming request.
- Path
Params - Extract (typed) path parameters from the path of an incoming request.
- RawPath
Params - Extract (raw) path parameters from the URL of an incoming request.
- RawPath
Params Iter - An iterator over the path parameters extracted via
RawPathParams.
Attribute Macros§
- Path
Params - Derive (de)serialization logic for a type that is going to be used to extract path parameters.