finchers icon indicating copy to clipboard operation
finchers copied to clipboard

Introduce ResponderExt

Open ubnt-intrepid opened this issue 5 years ago • 0 comments

trait ResponderExt: Responder {
    fn status(self, status: StatusCode) -> Status<Self>;
    fn content_type<S: AsRef<str>>(self, content_type: S) -> ContentType<Self, S>;
}

impl<T: Responder> ResponderExt for T {}

Usage

path("posts").and(path::param()).and(body::parse())
    .map(|id: u32, body: String| {
        format!("{{ \"id\":{}, \"body\":\"{}\" }}", id, escaped(body))
            .status(StatusCode::CREATED)
            .content_type("application/json")
    })

ubnt-intrepid avatar Aug 24 '18 18:08 ubnt-intrepid