pub struct Request { /* private fields */ }Expand description
An incoming request, already parsed and matched against a route.
Implementations§
Source§impl Request
impl Request
Sourcepub fn new(method: Method, target: impl Into<String>) -> Self
pub fn new(method: Method, target: impl Into<String>) -> Self
Build a request directly. This is what the test client and the server parser both go through.
pub fn method(&self) -> Method
Sourcepub fn route(&self) -> Option<&str>
pub fn route(&self) -> Option<&str>
The pattern this request matched: /users/{id}. Useful for metrics
that must not explode into one series per id.
pub fn headers(&self) -> &Headers
pub fn headers_mut(&mut self) -> &mut Headers
pub fn header(&self, name: &str) -> Option<&str>
pub fn body(&self) -> &[u8] ⓘ
pub fn body_string(&self) -> String
pub fn context(&self) -> &Context
pub fn config(&self) -> &Config
Sourcepub fn state<T: Send + Sync + 'static>(&self) -> Option<&T>
pub fn state<T: Send + Sync + 'static>(&self) -> Option<&T>
A service registered on the application: req.state::<Database>().
pub fn peer_addr(&self) -> Option<SocketAddr>
Sourcepub fn ip(&self) -> Option<String>
pub fn ip(&self) -> Option<String>
The client IP, honouring X-Forwarded-For when behind a proxy.
Sourcepub fn param(&self, name: &str) -> Option<&str>
pub fn param(&self, name: &str) -> Option<&str>
A route parameter: for /users/{id} matching /users/7, param("id")
is "7".
Sourcepub fn param_as<T: FromStr>(&self, name: &str) -> Option<T>
pub fn param_as<T: FromStr>(&self, name: &str) -> Option<T>
A route parameter parsed into a type, so a handler can ask for an id as a number without unwrapping twice.
pub fn params(&self) -> &BTreeMap<String, String>
pub fn query(&self, name: &str) -> Option<&str>
Sourcepub fn query_all(&self, name: &str) -> Vec<&str>
pub fn query_all(&self, name: &str) -> Vec<&str>
Every value for a repeated query key: ?tag=a&tag=b.
pub fn query_pairs(&self) -> &[(String, String)]
pub fn content_type(&self) -> Option<&str>
pub fn is_json(&self) -> bool
Sourcepub fn wants_json(&self) -> bool
pub fn wants_json(&self) -> bool
Whether the client wants JSON back — an API client or a fetch() call.
Sourcepub fn json(&mut self) -> Option<&Json>
pub fn json(&mut self) -> Option<&Json>
The body parsed as JSON, or None if it is absent or malformed.
Sourcepub fn input(&mut self, name: &str) -> Option<String>
pub fn input(&mut self, name: &str) -> Option<String>
One input value, looked up in the JSON body, then the form body, then
the query string — the resolution order of Laravel’s $request->input().
Sourcepub fn form(&mut self) -> &[(String, String)]
pub fn form(&mut self) -> &[(String, String)]
All decoded form fields of a application/x-www-form-urlencoded body.
Sourcepub fn extend<T: Send + Sync + 'static>(&mut self, value: T)
pub fn extend<T: Send + Sync + 'static>(&mut self, value: T)
Attach a value for later middleware or the handler to read.
Sourcepub fn api_version(&self) -> Option<&str>
pub fn api_version(&self) -> Option<&str>
The API version this request is for — from the route’s
Router::version group, or from the
VersionHeader middleware.
Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
The identifier the RequestId
middleware assigned, for log lines and error reports.
Sourcepub fn extension<T: Send + Sync + 'static>(&self) -> Option<&T>
pub fn extension<T: Send + Sync + 'static>(&self) -> Option<&T>
Read a value attached by earlier middleware.