Skip to content

Content Negotiation #4

Open
Open
@seanmonstar

Description

@seanmonstar

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, or Negotiate(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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or requestrfcExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions