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

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

Json extractor configuration

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

#[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_config(index, |cfg| {
                  cfg.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 R

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

Important traits for &'a mut R

Set custom error handler

Trait Implementations

impl<S> Default for JsonConfig<S>
[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>