Function rouille::input::json::json_input [] [src]

pub fn json_input<O>(request: &Request) -> Result<O, JsonError> where
    O: Decodable

Attempts to parse the request's body as JSON.

Returns an error if the content-type of the request is not JSON, or if the JSON is malformed.

Example

extern crate rustc_serialize;

fn route_handler(request: &Request) -> Response {
    #[derive(RustcDecodable)]
    struct Json {
        field1: String,
        field2: i32,
    }
 
    let json: Json = try_or_400!(rouille::input::json_input(request));
    Response::text(format!("field1's value is {}", json.field1))
}