Struct ntex::web::types::JsonConfig [−][src]
pub struct JsonConfig { /* fields omitted */ }
Expand description
Json extractor configuration
use ntex::http::error;
use ntex::web::{self, App, FromRequest, HttpResponse};
#[derive(serde::Deserialize)]
struct Info {
username: String,
}
/// deserialize `Info` from request's body, max payload size is 4kb
async fn index(info: web::types::Json<Info>) -> String {
format!("Welcome {}!", info.username)
}
fn main() {
let app = App::new().service(
web::resource("/index.html")
.app_data(
// change json extractor configuration
web::types::JsonConfig::default()
.limit(4096)
.content_type(|mime| { // <- accept text/plain content type
mime.type_() == mime::TEXT && mime.subtype() == mime::PLAIN
})
)
.route(web::post().to(index))
);
}
Implementations
Trait Implementations
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
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more