Skip to content

Routing

All routes in Pavex must be registered with the application Blueprint via its route method:

use pavex::blueprint::{router::GET, Blueprint};
use pavex::f;

pub fn blueprint() -> Blueprint {
    let mut bp = Blueprint::new();
    bp.route(GET, "/greet", f!(crate::routes::greet));
    bp
}

Blueprint::route expects three arguments: a method guard, a path pattern and a request handler.

As your application grows, you can choose to lean into Pavex's more advanced routing features:

  • Fallbacks, to customize the response returned when no route matches
  • Path prefixes, to reduce repetition in your route definitions
  • Domain guards, to serve different content based on the domain being requested