pub fn scope<T: IntoPattern, Err: ErrorRenderer>(path: T) -> Scope<Err>
Expand description
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 ntex::web;
let app = web::App::new().service(
web::scope("/{project_id}")
.service(web::resource("/path1").to(|| async { web::HttpResponse::Ok() }))
.service(web::resource("/path2").to(|| async { web::HttpResponse::Ok() }))
.service(web::resource("/path3").to(|| async { web::HttpResponse::MethodNotAllowed() }))
);
In the above example, three routes get added:
- /{project_id}/path1
- /{project_id}/path2
- /{project_id}/path3