This is what I want to achieve:
I have endpoints in the form /entity1/<id>/entity2/<id>/stuff, i.e.:
let route = warp::path("entity1")
.and(warp::path::param::<u64>())
.and(warp::path("entity2"))
.and(warp::path::param::<u64>())
.and(warp::path("stuff"))
.and(warp::path::end())
.and(with_auth(db.clone())) // Authenticates user using Authorization header
.and_then(handler_function);
I have several similar endpoints that load entity2 from the database, reject the request if it does not match to entity1, and do then stuff with the loaded entity. My idea is to create a filter that loads the entity from the database and passes it to the handler function (and does some validation, eventually rejecting the request) with something like .and(with_entity2(db.clone())) and
pub fn with_entity2(db: &Db) -> impl Filter<Extract = (Entity2,), Error = warp::Rejection> + Clone {
// Get path params here?
}
I guess I could use FullPath, but would need to parse it myself.
Is it possible to get the path params? Or is there a better option? I wouldn't need the extracted params anymore, but I don't want to do database queries before the user is authenticated and the whole path matches.
You can use
full()filter.