Struct actix_web::dev::JsonConfig
source · pub struct JsonConfig<S> { /* private fields */ }
Expand description
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.0.limit(4096) // <- change json extractor configuration
.error_handler(|err, req| { // <- create custom error response
error::InternalError::from_response(
err, HttpResponse::Conflict().finish()).into()
});
})
});
}
Implementations
sourceimpl<S> JsonConfig<S>
impl<S> JsonConfig<S>
sourcepub fn limit(&mut self, limit: usize) -> &mut Self
pub fn limit(&mut self, limit: usize) -> &mut Self
Change max size of payload. By default max size is 256Kb
sourcepub fn error_handler<F>(&mut self, f: F) -> &mut Selfwhere
F: Fn(JsonPayloadError, &HttpRequest<S>) -> Error + 'static,
pub fn error_handler<F>(&mut self, f: F) -> &mut Selfwhere
F: Fn(JsonPayloadError, &HttpRequest<S>) -> Error + 'static,
Set custom error handler
Trait Implementations
Auto Trait Implementations
impl<S> !RefUnwindSafe for JsonConfig<S>
impl<S> !Send for JsonConfig<S>
impl<S> !Sync for JsonConfig<S>
impl<S> Unpin for JsonConfig<S>
impl<S> !UnwindSafe for JsonConfig<S>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more