Available on crate feature
http only.Expand description
Getting a request’s body into your own types.
A handler should receive one Context carrying everything the request
turned into, not a widening tuple of extractors. FromRequest is where
you say how that happens: read the body however you like, produce your
type, and the generated routes attach it to the context for you.
impl FromRequest<App> for NewTodo {
async fn from_request(req: Request, app: &App, ctx: &Context) -> Result<Self, Errors> {
// The JSON:API path: validate against the resource's schema, then
// map the document. `validated` does the first half.
let doc = validated(req, ctx, app.validator("todo")).await?;
Ok(NewTodo { message: doc["data"]["attributes"]["message"].as_str()… })
}
}Nothing here assumes JSON. A resource whose create body is multipart, or form-encoded, or a raw upload, implements the same trait and reads the request its own way.
Structs§
- Jsonl
Lines streaming - A request body, split into lines as it arrives.
- Upload
- A raw request body — an uploaded file, rather than a JSON:API document.
Constants§
- MAX_
BODY - The largest body
body_textwill read: 2 MiB. - MAX_
LINE streaming - The largest single line
JsonlLineswill read: 1 MiB. - MAX_
UPLOAD - The largest
Uploadread by default: 10 MiB.
Traits§
- From
Request - Build
Selffrom a request.
Functions§
- body_
text - Read a request body as UTF-8 text.
- check_
media_ type - Check that a request carries a JSON:API body.
- path_id
- The
ida document addresses, from the request path. - validated
validation - Read a body and check it against a resource’s request schema.