Crates.io | gotham_serde_json_body_parser |
lib.rs | gotham_serde_json_body_parser |
version | 0.2.0 |
source | src |
created_at | 2018-03-26 12:51:27.254311 |
updated_at | 2018-03-28 16:03:32.919076 |
description | JSON body parser for the Gotham web framework. |
homepage | |
repository | https://github.com/ChristophWurst/gotham-serde-json-body-parser |
max_upload_size | |
id | 57588 |
size | 6,908 |
JSON body parser for the Gotham web framework.
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))
}))
}