mirror of https://github.com/fafhrd91/actix-web
Update FromRequest doc
This commit is contained in:
parent
64d7f8786c
commit
4e59376d62
|
@ -11,9 +11,46 @@ use futures_core::ready;
|
||||||
|
|
||||||
use crate::{dev::Payload, Error, HttpRequest};
|
use crate::{dev::Payload, Error, HttpRequest};
|
||||||
|
|
||||||
/// Trait implemented by types that can be extracted from request.
|
/// [`FromRequest`] is one of the most commonly used trait, although some may not realize it.
|
||||||
///
|
///
|
||||||
/// Types that implement this trait can be used with `Route` handlers.
|
/// A type that implements [`FromRequest`] is called an **extractor** and can be extracted
|
||||||
|
/// from the request, for example [`Json`], [`Form`], [`Path`] and so on.
|
||||||
|
///
|
||||||
|
/// An extractor can be customized by injecting the corresponding configuration with:
|
||||||
|
///
|
||||||
|
/// - [`App::data()`](`crate::App::data`)
|
||||||
|
/// - [`App::app_data()`](`crate::App::app_data`)
|
||||||
|
/// - [`Scope::data()`](`crate::Scope::data`)
|
||||||
|
/// - [`Scope::app_data()`](`crate::Scope::app_data`)
|
||||||
|
/// - [`Resource::data()`](`crate::Resource::data`)
|
||||||
|
/// - [`Resource::app_data()`](`crate::Resource::app_data`)
|
||||||
|
///
|
||||||
|
/// Here are some built-in extractors and their corresponding configuration.
|
||||||
|
/// Please refer to the respective documents for details.
|
||||||
|
///
|
||||||
|
/// | Extractor | Configuration |
|
||||||
|
/// |-------------|-------------------|
|
||||||
|
/// | [`Json`] | [`JsonConfig`] |
|
||||||
|
/// | [`Form`] | [`FormConfig`] |
|
||||||
|
/// | [`Path`] | [`PathConfig`] |
|
||||||
|
/// | [`Query`] | [`QueryConfig`] |
|
||||||
|
/// | [`Payload`] | [`PayloadConfig`] |
|
||||||
|
/// | [`String`] | [`PayloadConfig`] |
|
||||||
|
/// | [`Bytes`] | [`PayloadConfig`] |
|
||||||
|
///
|
||||||
|
/// [`Json`]: crate::web::Json
|
||||||
|
/// [`JsonConfig`]: crate::web::JsonConfig
|
||||||
|
/// [`Form`]: crate::web::Form
|
||||||
|
/// [`FormConfig`]: crate::web::FormConfig
|
||||||
|
/// [`Path`]: crate::web::Path
|
||||||
|
/// [`PathConfig`]: crate::web::PathConfig
|
||||||
|
/// [`Query`]: crate::web::Query
|
||||||
|
/// [`QueryConfig`]: crate::web::QueryConfig
|
||||||
|
/// [`Payload`]: crate::web::Payload
|
||||||
|
/// [`PayloadConfig`]: crate::web::PayloadConfig
|
||||||
|
/// [`String`]: FromRequest#impl-FromRequest-for-String
|
||||||
|
/// [`Bytes`]: crate::web::Bytes#impl-FromRequest
|
||||||
|
#[doc(alias = "Extractor")]
|
||||||
pub trait FromRequest: Sized {
|
pub trait FromRequest: Sized {
|
||||||
/// The associated error which can be returned.
|
/// The associated error which can be returned.
|
||||||
type Error: Into<Error>;
|
type Error: Into<Error>;
|
||||||
|
|
|
@ -123,8 +123,7 @@ impl<'a> Future for BytesExtractFut {
|
||||||
///
|
///
|
||||||
/// Text extractor automatically decode body according to the request's charset.
|
/// Text extractor automatically decode body according to the request's charset.
|
||||||
///
|
///
|
||||||
/// [**PayloadConfig**](PayloadConfig) allows to configure
|
/// Use [`PayloadConfig`] to configure extraction process.
|
||||||
/// extraction process.
|
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -194,14 +193,15 @@ fn bytes_to_string(body: Bytes, encoding: &'static Encoding) -> Result<String, E
|
||||||
|
|
||||||
/// Configuration for request payloads.
|
/// Configuration for request payloads.
|
||||||
///
|
///
|
||||||
/// Applies to the built-in `Bytes` and `String` extractors. Note that the `Payload` extractor does
|
/// Applies to the built-in [`Bytes`] and [`String`] extractors.
|
||||||
/// not automatically check conformance with this configuration to allow more flexibility when
|
/// Note that the [`Payload`] extractor does not automatically check
|
||||||
/// building extractors on top of `Payload`.
|
/// conformance with this configuration to allow more flexibility when
|
||||||
|
/// building extractors on top of [`Payload`].
|
||||||
///
|
///
|
||||||
/// By default, the payload size limit is 256kB and there is no mime type condition.
|
/// By default, the payload size limit is 256kB and there is no mime type condition.
|
||||||
///
|
///
|
||||||
/// To use this, add an instance of it to your app or service through one of the
|
/// To use this, add an instance of it to your [`app`](crate::App), [`scope`](crate::Scope)
|
||||||
/// `.app_data()` methods.
|
/// or [`resource`](crate::Resource) through the associated `.app_data()` or `.data()` method.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct PayloadConfig {
|
pub struct PayloadConfig {
|
||||||
limit: usize,
|
limit: usize,
|
||||||
|
|
Loading…
Reference in New Issue