diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index 22aabca7e8b..06ab75871a5 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -1,7 +1,10 @@ # Changelog ## Unreleased - 2021-xx-xx -- Add `ServiceRequest::extract` to make it easier to use extractors when writing middlewares. +- Add `ServiceRequest::extract` to make it easier to use extractors when writing middlewares. [#2647] + +[#2647]: https://github.com/actix/actix-web/pull/2647 + ## 4.0.1 - 2022-02-25 ### Fixed diff --git a/actix-web/src/extract.rs b/actix-web/src/extract.rs index df17a669096..1b2f0bd197c 100644 --- a/actix-web/src/extract.rs +++ b/actix-web/src/extract.rs @@ -18,12 +18,11 @@ use crate::{dev::Payload, Error, HttpRequest}; /// A type that implements [`FromRequest`] is called an **extractor** and can extract data from /// the request. Some types that implement this trait are: [`Json`], [`Header`], and [`Path`]. /// -/// Check out [`ServiceRequest::extract`](crate::dev::ServiceRequest::extract) if you want to leverage -/// extractors when implementing middlewares. +/// Check out [`ServiceRequest::extract`](crate::dev::ServiceRequest::extract) if you want to +/// leverage extractors when implementing middlewares. /// /// # Configuration /// An extractor can be customized by injecting the corresponding configuration with one of: -/// /// - [`App::app_data()`][crate::App::app_data] /// - [`Scope::app_data()`][crate::Scope::app_data] /// - [`Resource::app_data()`][crate::Resource::app_data] diff --git a/actix-web/src/service.rs b/actix-web/src/service.rs index 7bdf04bfd3b..a2775f41e80 100644 --- a/actix-web/src/service.rs +++ b/actix-web/src/service.rs @@ -95,25 +95,25 @@ impl ServiceRequest { (&mut self.req, &mut self.payload) } - /// Use an [extractor](crate::FromRequest) to build a type out of the incoming request. + /// Derives a type from this request using an [extractor](crate::FromRequest). /// - /// `extract` is particularly handy when you need to use an extractor inside - /// a middleware implementation. + /// Returns the extractor's future type, which can be `await`ed. This is particularly handy when + /// you want to use an extractor in a middleware implementation. /// - /// # Example - /// - /// ```rust - /// use actix_web::dev::{ServiceRequest, ServiceResponse}; - /// use actix_web::web::Path; - /// use actix_web::Error; + /// # Examples + /// ``` + /// use actix_web::{ + /// dev::{ServiceRequest, ServiceResponse}, + /// web::Path, Error + /// }; /// - /// async fn f(mut service_request: ServiceRequest) -> Result { - /// let path = service_request.extract::>().await?; + /// async fn my_helper(mut srv_req: ServiceRequest) -> Result { + /// let path = srv_req.from_request::>().await?; /// // [...] /// # todo!() /// } /// ``` - pub fn extract(&mut self) -> ::Future + pub fn from_request(&mut self) -> ::Future where T: FromRequest, {