pub struct JsonConfig { /* private fields */ }Expand description
Json extractor configuration
use ntex::http::error;
use ntex::web::{self, App, FromRequest, HttpResponse, WebAppConfig};
#[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 cfg = WebAppConfig::new()
.set_state(
// 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
}));
let app = App::default()
.with_config(cfg)
.service(web::resource("/index.html")
.route(web::post().to(index))
);
}Implementations§
Trait Implementations§
Source§impl Clone for JsonConfig
impl Clone for JsonConfig
Source§fn clone(&self) -> JsonConfig
fn clone(&self) -> JsonConfig
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for JsonConfig
impl Debug for JsonConfig
Auto Trait Implementations§
impl !RefUnwindSafe for JsonConfig
impl !UnwindSafe for JsonConfig
impl Freeze for JsonConfig
impl Send for JsonConfig
impl Sync for JsonConfig
impl Unpin for JsonConfig
impl UnsafeUnpin for JsonConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more