Struct actix_web_validator::JsonConfig [−][src]
pub struct JsonConfig { /* fields omitted */ }Expand description
Json extractor configuration
use actix_web::{error, web, App, FromRequest, HttpResponse}; use serde::Deserialize; use actix_web_validator::{Json, JsonConfig}; use validator::Validate; #[derive(Deserialize, Validate)] struct Info { #[validate(length(min = 3))] username: String, } /// deserialize `Info` from request's body, max payload size is 4kb async fn index(info: Json<Info>) -> String { format!("Welcome {}!", info.username) } fn main() { let app = App::new().service( web::resource("/index.html") .app_data( // change json extractor configuration Json::<Info>::configure(|cfg| { cfg.limit(4096) .content_type(|mime| { // <- accept text/plain content type mime.type_() == mime::TEXT && mime.subtype() == mime::PLAIN }) .error_handler(|err, req| { // <- create custom error response error::InternalError::from_response( err, HttpResponse::Conflict().finish()).into() }) })) .route(web::post().to(index)) ); }
Implementations
Change max size of payload. By default max size is 32Kb
pub fn error_handler<F>(self, f: F) -> Self where
F: Fn(Error, &HttpRequest) -> Error + Send + Sync + 'static, [src]
pub fn error_handler<F>(self, f: F) -> Self where
F: Fn(Error, &HttpRequest) -> Error + Send + Sync + 'static, [src]Set custom error handler
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for JsonConfigimpl Send for JsonConfigimpl Sync for JsonConfigimpl Unpin for JsonConfigimpl !UnwindSafe for JsonConfigBlanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span, returning an
Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an
Instrumented wrapper. Read more
type Output = T
type Output = TShould always be Self
pub fn vzip(self) -> V