Type signature
As an extractor
TheForm extractor deserializes form data from the request. The behavior depends on the request method:
- GET or HEAD requests: Form data is read from the query string (same as
Query) - Other methods: Form data is read from the request body with
Content-Type: application/x-www-form-urlencoded
Basic usage
Optional fields
UseOption for optional form fields:
Multiple values
Form fields with the same name can be collected into aVec:
As a response
Form can encode any type that implements serde::Serialize as application/x-www-form-urlencoded:
Error handling
Extractor rejections
415
The request method is not GET/HEAD and the content-type is not
application/x-www-form-urlencoded.400
Failed to deserialize form data from query string (GET/HEAD requests).
422
Failed to deserialize form data from request body (other methods).
Example errors
GET vs POST behavior
TheForm extractor automatically handles both query strings and request bodies:
Multipart forms
Formultipart/form-data (file uploads), use the Multipart extractor instead: