Skip to content
This repository has been archived by the owner on Jan 18, 2020. It is now read-only.

Introduce ResponderExt #279

Open
ubnt-intrepid opened this issue Aug 24, 2018 · 0 comments
Open

Introduce ResponderExt #279

ubnt-intrepid opened this issue Aug 24, 2018 · 0 comments

Comments

@ubnt-intrepid
Copy link
Contributor

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")
    })
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant