2 unstable releases

Uses old Rust 2015

0.2.0 Mar 28, 2018
0.1.0 Mar 26, 2018

#15 in #gotham

Download history 3/week @ 2024-02-19 14/week @ 2024-02-26 7/week @ 2024-03-11 1/week @ 2024-03-18 56/week @ 2024-04-01

57 downloads per month

MIT license

5KB
68 lines

gotham-serde-json-body-parser

JSON body parser for the Gotham web framework.

Crates.io

This is a simple integration of serde_json crate to eliminate the boilerplate code of parsing a request body. If parsing fails, a HTTP 422 (Unprocessable entity) is returned. This crate also provides a convenience function to create JSON responses.

use gotham_serde_json_body_parser::{create_json_response, JSONBody};

#[derive(Debug, Deserialize, Serialize)]
struct Person {
    name: String,
}

pub fn json_echo(state: State) -> Box<HandlerFuture> {
    Box::new(state.json::<Person>().and_then(|(state, person)| {
        let res = create_json_response(&state, StatusCode::Ok, &person).unwrap();
        Ok((state, res))
    }))
}

Dependencies

~18MB
~356K SLoC