liveBook · Manning

Route parameter

As explained in Rust Servers, Services, and Apps

A URL path parameter is a variable value embedded in a URL path and supplied to the operation selected by that route.

A route parameter is a variable value embedded in a URL path and passed to the handler selected by that route. In Actix, a route such as `/{tutor_id}` supplies the tutor identifier used to filter courses. section 3.2.5

Route parameters connect URL structure, handler arguments, and resource lookup:

Nested course lookup

A request to `/courses/1/1` maps `tutor_id` and `course_id` to `web::Path<(i32, i32)>`; the handler returns the course matching both values. Tests construct the same path value manually. section 3.2.6

pub fn course_routes(cfg: &mut web::ServiceConfig) {
  cfg.service(
    web::scope("/courses")
     .route("/", web::post().to(new_course))
     .route("/{tutor_id}", web::get().to(get_courses_for_tutor))
     .route("/{tutor_id}/{course_id}", web::get().to(get_course_detail)), #1
  );
}

Inspect the route declaration that binds two URL segments to the single-course handler. section 3.2.6

How Rust Servers, Services, and Apps covers it

How deep it goes
Explains route declarations, typed extraction, filtering, database calls, and manual tests, while deferring exhaustive success and failure coverage.
Examples
Uses `/courses/1`, `/courses/1/1`, tuple extraction, course filtering, tutor lookup, and Actix handler tests.
What you can do after
Apply via Actix by declaring typed path placeholders, extracting values, and passing them to filtering or database operations.
How it connects
Connects URL paths with route configuration, handler functions, application state, database access, and HTTP responses.

Also explained in

Compare how 6 books explain route parameter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.