Struct actix_web::dev::JsonConfig [] [src]

pub struct JsonConfig<S> { /* fields omitted */ }

Json extractor configuration

#[macro_use] extern crate serde_derive;
use actix_web::{App, Json, HttpResponse, Result, http, error};

#[derive(Deserialize)]
struct Info {
    username: String,
}

/// deserialize `Info` from request's body, max payload size is 4kb
fn index(info: Json<Info>) -> Result<String> {
    Ok(format!("Welcome {}!", info.username))
}

fn main() {
    let app = App::new().resource(
       "/index.html", |r| {
           r.method(http::Method::POST)
              .with(index)
              .limit(4096)   // <- change json extractor configuration
              .error_handler(|err, req| {  // <- create custom error response
                  error::InternalError::from_response(
                     err, HttpResponse::Conflict().finish()).into()
              });
       });
}

Methods

impl<S> JsonConfig<S>
[src]

Important traits for &'a mut W
[src]

Change max size of payload. By default max size is 256Kb

Important traits for &'a mut W
[src]

Set custom error handler

Trait Implementations

impl<S> Default for JsonConfig<S>
[src]

[src]

Returns the "default value" for a type. Read more

Auto Trait Implementations

impl<S> !Send for JsonConfig<S>

impl<S> !Sync for JsonConfig<S>