pub fn json_input<O>(request: &Request) -> Result<O, JsonError>where
O: DeserializeOwned,
Expand description
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
fn main() {}
fn route_handler(request: &Request) -> Response {
#[derive(Deserialize)]
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))
}