[][src]Struct actix_web::web::Form

pub struct Form<T>(pub T);

Form data helper (application/x-www-form-urlencoded)

Can be use to extract url-encoded data from the request body, or send url-encoded data as the response.

Extract

To extract typed information from request's body, the type T must implement the Deserialize trait from serde.

FormConfig allows to configure extraction process.

Example

#[macro_use] extern crate serde_derive;
use actix_web::{web, App};

#[derive(Deserialize)]
struct FormData {
    username: String,
}

/// Extract form data using serde.
/// This handler get called only if content type is *x-www-form-urlencoded*
/// and content of the request could be deserialized to a `FormData` struct
fn index(form: web::Form<FormData>) -> String {
    format!("Welcome {}!", form.username)
}

Respond

The Form type also allows you to respond with well-formed url-encoded data: simply return a value of type Form where T is the type to be url-encoded. The type must implement serde::Serialize;

Example

#[derive(Serialize)]
struct SomeForm {
    name: String,
    age: u8
}

// Will return a 200 response with header
// `Content-Type: application/x-www-form-urlencoded`
// and body "name=actix&age=123"
fn index() -> web::Form<SomeForm> {
    web::Form(SomeForm {
        name: "actix".into(),
        age: 123
    })
}

Methods

impl<T> Form<T>[src]

pub fn into_inner(self) -> T[src]

Deconstruct to an inner value

Trait Implementations

impl<T> FromRequest for Form<T> where
    T: DeserializeOwned + 'static, 
[src]

type Config = FormConfig

Configuration for this extractor

type Error = Error

The associated error which can be returned.

type Future = Box<dyn Future<Item = Self, Error = Error>>

Future that resolves to a Self

fn extract(req: &HttpRequest) -> Self::Future[src]

Convert request to a Self Read more

fn configure<F>(f: F) -> Self::Config where
    F: FnOnce(Self::Config) -> Self::Config
[src]

Create and configure config instance.

impl<T: Serialize> Responder for Form<T>[src]

type Error = Error

The associated error which can be returned.

type Future = Result<Response, Error>

The future response value.

fn with_status(self, status: StatusCode) -> CustomResponder<Self> where
    Self: Sized
[src]

Override a status code for a Responder. Read more

fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self> where
    Self: Sized,
    HeaderName: HttpTryFrom<K>,
    V: IntoHeaderValue
[src]

Add header to the Responder's response. Read more

impl<T: Ord> Ord for Form<T>[src]

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl<T: PartialOrd> PartialOrd<Form<T>> for Form<T>[src]

impl<T: PartialEq> PartialEq<Form<T>> for Form<T>[src]

impl<T: Eq> Eq for Form<T>[src]

impl<T> DerefMut for Form<T>[src]

impl<T> Deref for Form<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T: Display> Display for Form<T>[src]

impl<T: Debug> Debug for Form<T>[src]

Auto Trait Implementations

impl<T> Send for Form<T> where
    T: Send

impl<T> Unpin for Form<T> where
    T: Unpin

impl<T> Sync for Form<T> where
    T: Sync

impl<T> UnwindSafe for Form<T> where
    T: UnwindSafe

impl<T> RefUnwindSafe for Form<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> Erased for T

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T, A, P> Access<T> for P where
    A: Access<T>,
    P: Deref<Target = A>, 
[src]

type Guard = <A as Access<T>>::Guard

A guard object containing the value and keeping it alive. Read more

impl<T, A> DynAccess<T> for A where
    A: Access<T>,
    <A as Access<T>>::Guard: 'static, 
[src]