actix-web
actix-web copied to clipboard
Introduce `Group`
PR Type
Feature
PR Checklist
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] A changelog entry has been made for the appropriate packages.
- [ ] Format code with the latest stable rustfmt.
- [x] (Team) Label with affected crates and semver status.
Overview
This tries to implement #414 . I implemented these changes on Scope temporarily to use existing tests and for smaller diff.
The new behavior for scope is equivalent to registering component services individually. This allows the scope to fallthrough when no matching route is found (instead of calling default service). A typical use case would be:
app
.service(
web::scope("/users")
.wrap(no_auth_needed)
.route("u1", web::get().to(handle_u1))
.route("u2", web::get().to(handle_u2)),
)
.service(
web::scope("/users")
.wrap(need_auth)
.route("{user}", handle_other_users),
)
Setting Scope::default_service(), would make it mimic the original behavior.
As a side-effect, this will also make #2096 possible.
Open questions
This introduces new API. So I'm looking for input before finishing it. Specifically, I'm looking for the naming (eg. EndpointConstructor trait) and what mehods to have for it.
Closes #414 Closes #2096