Struct ajars_actix_web::actix_web::web::JsonConfig [−][src]
pub struct JsonConfig { /* fields omitted */ }
Expand description
Json
extractor configuration.
Examples
use actix_web::{error, post, web, App, FromRequest, HttpResponse}; use serde::Deserialize; #[derive(Deserialize)] struct Info { name: String, } // `Json` extraction is bound by custom `JsonConfig` applied to App. #[post("/")] async fn index(info: web::Json<Info>) -> String { format!("Welcome {}!", info.name) } // custom `Json` extractor configuration let json_cfg = web::JsonConfig::default() // limit request payload size .limit(4096) // only accept text/plain content type .content_type(|mime| mime == mime::TEXT_PLAIN) // use custom error handler .error_handler(|err, req| { error::InternalError::from_response(err, HttpResponse::Conflict().into()).into() }); App::new() .app_data(json_cfg) .service(index);
Implementations
Set maximum accepted payload size. By default this limit is 2MB.
pub fn error_handler<F>(self, f: F) -> JsonConfig where
F: Fn(JsonPayloadError, &HttpRequest) -> Error + Send + Sync + 'static,
pub fn error_handler<F>(self, f: F) -> JsonConfig where
F: Fn(JsonPayloadError, &HttpRequest) -> Error + Send + Sync + 'static,
Set custom error handler.
pub fn content_type<F>(self, predicate: F) -> JsonConfig where
F: Fn(Mime) -> bool + Send + Sync + 'static,
pub fn content_type<F>(self, predicate: F) -> JsonConfig where
F: Fn(Mime) -> bool + Send + Sync + 'static,
Set predicate for allowed content types.
Trait Implementations
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl !RefUnwindSafe for JsonConfig
impl Send for JsonConfig
impl Sync for JsonConfig
impl Unpin for JsonConfig
impl !UnwindSafe for JsonConfig
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
type Output = T
type Output = T
Should always be Self
pub fn vzip(self) -> V