Routing configuration maps incoming URL paths and HTTP methods to handler functions. In an Actix Web service, the application inspects the configured routes, selects the matching handler, and forwards the request with application state and path parameters. section 3.2.1
Build the course routes incrementally in src/routes.rs:
- Group endpoints under the /courses scope and map POST / to new_course. section 3.2.5
- Map GET /{tutor_id} to get_courses_for_tutor; the handler receives application state and a tutor identifier, then returns matching courses. section 3.2.5
- Add GET /{tutor_id}/{course_id} for get_course_detail, using two path parameters to locate one course. section 3.2.6
Testing and exercising the routes
Test handlers by constructing AppState and web::Path values, invoking the async function, and asserting the HTTP status. Run the service with cargo run, create courses with curl, then request localhost:3000/courses/1 or localhost:3000/courses/1/1 to inspect the responses. section 3.2.5 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)), #1
);
}
Inspect the concrete Actix route declaration for the course collection and tutor-filtered GET endpoint. section 3.2.5
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 completed route group, including the nested path for retrieving a single course. section 3.2.6

