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

pub struct Form<T>(pub T);

URL encoded payload extractor and responder.

Form has two uses: URL encoded responses, and extracting typed data from URL request payloads.

Extractor

To extract typed data from a request body, the inner type T must implement the serde::Deserialize trait.

Use FormConfig to configure extraction process.

use actix_web::{post, web};
use serde::Deserialize;

#[derive(Deserialize)]
struct Info {
    name: String,
}

// This handler is only called if:
// - request headers declare the content type as `application/x-www-form-urlencoded`
// - request payload is deserialized into a `Info` struct from the URL encoded format
#[post("/")]
async fn index(form: web::Form<Info>) -> String {
    format!("Welcome {}!", form.name)
}

Responder

The Form type also allows you to create URL encoded responses: simply return a value of type Form where T is the type to be URL encoded. The type must implement serde::Serialize.

Responses use

use actix_web::{get, web};
use serde::Serialize;

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

// Response will have:
// - status: 200 OK
// - header: `Content-Type: application/x-www-form-urlencoded`
// - body: `name=actix&age=123`
#[get("/")]
async fn index() -> web::Form<SomeForm> {
    web::Form(SomeForm {
        name: "actix".into(),
        age: 123
    })
}

Implementations

impl<T> Form<T>[src]

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

Unwrap into inner T value.

Trait Implementations

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

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

type Target = T

The resulting type after dereferencing.

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

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

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

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

See here for example of usage as an extractor.

type Config = FormConfig

Configuration for this extractor.

type Error = Error

The associated error which can be returned.

type Future = LocalBoxFuture<'static, Result<Self, Error>>

Future that resolves to a Self.

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

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

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

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

See here for example of usage as a handler return type.

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

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

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

Auto Trait Implementations

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

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

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

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

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

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

impl<T> Instrument for T[src]

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

impl<T> Same<T> for T

type Output = T

Should always be Self

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<V, T> VZip<V> for T where
    V: MultiLane<T>,