Skip to content
This repository has been archived by the owner on Jun 25, 2018. It is now read-only.

JSON body parser for the Gotham web framework

License

Notifications You must be signed in to change notification settings

ChristophWurst/gotham-serde-json-body-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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))
    }))
}

About

JSON body parser for the Gotham web framework

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages