pub struct JsonRequest<T>(pub T);Expand description
Axum extractor that deserializes a JSON request body into T and then sanitizes it.
Returns a 400 Bad Request error if the body is not valid JSON or cannot be
deserialized. T must implement both serde::de::DeserializeOwned and
crate::sanitize::Sanitize.
§Example
use modo::extractor::JsonRequest;
use modo::sanitize::Sanitize;
use serde::Deserialize;
#[derive(Deserialize)]
struct CreateItem { name: String }
impl Sanitize for CreateItem {
fn sanitize(&mut self) { self.name = self.name.trim().to_string(); }
}
async fn create(JsonRequest(body): JsonRequest<CreateItem>) {
// body.name is already trimmed
}Tuple Fields§
§0: TTrait Implementations§
Source§impl<S, T> FromRequest<S> for JsonRequest<T>
impl<S, T> FromRequest<S> for JsonRequest<T>
Auto Trait Implementations§
impl<T> Freeze for JsonRequest<T>where
T: Freeze,
impl<T> RefUnwindSafe for JsonRequest<T>where
T: RefUnwindSafe,
impl<T> Send for JsonRequest<T>where
T: Send,
impl<T> Sync for JsonRequest<T>where
T: Sync,
impl<T> Unpin for JsonRequest<T>where
T: Unpin,
impl<T> UnsafeUnpin for JsonRequest<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for JsonRequest<T>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