My API routes are collected into a scope like so:
.scope("/api", |s| s
.nested("/doorlock", routes::doorlock)
.resource("/config{path:.*}", |r| {
r.get().with(routes::config::read);
r.put().with(routes::config::write);
r.delete().with(routes::config::delete);
})
)
I am thinking about adding a route-level protection, something that would either pass-through or return a 401 Unauthorizated
response like so:
.scope("/api", |s| s
.filter(is_authenticated_and_authorized)
.nested("/doorlock", routes::doorlock)
.resource("/config{path:.*}", |r| {
r.get().with(routes::config::read);
r.put().with(routes::config::write);
r.delete().with(routes::config::delete);
})
)
Unfortunately, this will forward requests to the default handler rather than returning an error response in case it does not match.