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::{Json, DEFAULT_JSON_LIMIT};
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> Freeze for Json<T, LIMIT>where
T: Freeze,
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 A
impl<T, A> DynAccess<T> for A
source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of
Access::load
.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more