Expand description
Create a Filter
that requires the request method to be DELETE
.
Example
use warp::Filter;
let delete_only = warp::delete().map(warp::reply);
Examples found in repository?
examples/todos.rs (line 94)
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
pub fn todos_delete(
db: Db,
) -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
// We'll make one of our endpoints admin-only to show how authentication filters are used
let admin_only = warp::header::exact("authorization", "Bearer admin");
warp::path!("todos" / u64)
// It is important to put the auth check _after_ the path filters.
// If we put the auth check before, the request `PUT /todos/invalid-string`
// would try this filter and reject because the authorization header doesn't match,
// rather because the param is wrong for that other path.
.and(admin_only)
.and(warp::delete())
.and(with_db(db))
.and_then(handlers::delete_todo)
}