[][src]Function actix_web::web::scope

pub fn scope(path: &str) -> Scope

Configure scope for common root path.

Scopes collect multiple paths under a common path prefix. Scope path can contain variable path segments as resources.

use actix_web::{web, App, HttpResponse};

let app = App::new().service(
    web::scope("/{project_id}")
        .service(web::resource("/path1").to(|| HttpResponse::Ok()))
        .service(web::resource("/path2").to(|| HttpResponse::Ok()))
        .service(web::resource("/path3").to(|| HttpResponse::MethodNotAllowed()))
);

In the above example, three routes get added:

  • /{project_id}/path1
  • /{project_id}/path2
  • /{project_id}/path3