pub struct Form<T>(pub T);Expand description
URL-encoded form data extractor.
Extracts application/x-www-form-urlencoded form data from the request body
and deserializes it into the target type using serde.
§Example
ⓘ
use fastapi_core::Form;
use serde::Deserialize;
#[derive(Deserialize)]
struct LoginForm {
username: String,
password: String,
}
async fn login(Form(form): Form<LoginForm>) -> impl IntoResponse {
format!("Login attempt for: {}", form.username)
}§Content-Type
This extractor expects the Content-Type header to be
application/x-www-form-urlencoded. Other content types will result
in an error.
§Error Responses
Returns 422 Unprocessable Entity when:
- Content-Type is not
application/x-www-form-urlencoded - Body cannot be read
- Deserialization fails
Tuple Fields§
§0: TImplementations§
Trait Implementations§
Source§impl<T> FromRequest for Form<T>
impl<T> FromRequest for Form<T>
Source§type Error = FormExtractError
type Error = FormExtractError
Error type when extraction fails.
Source§async fn from_request(
ctx: &RequestContext,
req: &mut Request,
) -> Result<Self, Self::Error>
async fn from_request( ctx: &RequestContext, req: &mut Request, ) -> Result<Self, Self::Error>
Extract a value from the request. Read more
Auto Trait Implementations§
impl<T> Freeze for Form<T>where
T: Freeze,
impl<T> RefUnwindSafe for Form<T>where
T: RefUnwindSafe,
impl<T> Send for Form<T>where
T: Send,
impl<T> Sync for Form<T>where
T: Sync,
impl<T> Unpin for Form<T>where
T: Unpin,
impl<T> UnwindSafe for Form<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).