Open
Description
Provide a content-negotiation filter with these objectives:
- User can chain together serializers, choosing what formats can be output.
- Serializers include
content-type
headers - The filter checks for "best" serializer using the request's
accept
header. - Wrapped filters can return either
T: Serialize
, orNegotiate(Response<T: Serialize>)
, which will automatically be serialized by the "best" format.
Example:
let negotiation = warp::reply::with::negotiate()
.format(json)
.format(xml);
let list = warp::path("todos")
.and_then(|| DB::load_todos());
let one = path!("todos" / u64)
.and_then(|id| Db::get_todo(id));
let api = list.or(one)
.with(negotiate);