Struct actix_web_lab::extract::Json
source · pub struct Json<T, const LIMIT: usize = DEFAULT_JSON_LIMIT>(pub T);
Expand description
JSON extractor with const-generic payload size limit.
Json
is used to extract typed data from JSON request payloads.
Extractor
To extract typed data from a request body, the inner type T
must implement the
serde::Deserialize
trait.
Use the LIMIT
const generic parameter to control the payload size limit. The default limit
that is exported (DEFAULT_LIMIT
) is 2MiB.
use actix_web::{post, App};
use actix_web_lab::extract::{DEFAULT_JSON_LIMIT, Json};
use serde::Deserialize;
#[derive(Deserialize)]
struct Info {
username: String,
}
/// Deserialize `Info` from request's body.
#[post("/")]
async fn index(info: Json<Info>) -> String {
format!("Welcome {}!", info.username)
}
const LIMIT_32_MB: usize = 33_554_432;
/// Deserialize payload with a higher 32MiB limit.
#[post("/big-payload")]
async fn big_payload(info: Json<Info, LIMIT_32_MB>) -> String {
format!("Welcome {}!", info.username)
}
Tuple Fields§
§0: T
Implementations§
Trait Implementations§
source§impl<T: DeserializeOwned, const LIMIT: usize> FromRequest for Json<T, LIMIT>
impl<T: DeserializeOwned, const LIMIT: usize> FromRequest for Json<T, LIMIT>
See here for example of usage as an extractor.
source§fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
Create a
Self
from request parts asynchronously.Auto Trait Implementations§
impl<T, const LIMIT: usize> RefUnwindSafe for Json<T, LIMIT>where T: RefUnwindSafe,
impl<T, const LIMIT: usize> Send for Json<T, LIMIT>where T: Send,
impl<T, const LIMIT: usize> Sync for Json<T, LIMIT>where T: Sync,
impl<T, const LIMIT: usize> Unpin for Json<T, LIMIT>where T: Unpin,
impl<T, const LIMIT: usize> UnwindSafe for Json<T, LIMIT>where T: UnwindSafe,
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
source§impl<T, A> DynAccess<T> for Awhere
A: Access<T>,
<A as Access<T>>::Guard: 'static,
impl<T, A> DynAccess<T> for Awhere A: Access<T>, <A as Access<T>>::Guard: 'static,
source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of
Access::load
.