[−][src]Struct tide::Context
Data associated with a request-response lifecycle.
The Context
gives endpoints access to basic information about the incoming
request, route parameters, and various ways of accessing the request's body.
Contexts also provide extensions, a type map primarily used for low-level communication between middleware and endpoints.
Methods
impl<AppData> Context<AppData>
[src]
pub fn method(&self) -> &Method
[src]
Access the request's HTTP method.
pub fn uri(&self) -> &Uri
[src]
Access the request's full URI method.
pub fn version(&self) -> Version
[src]
Access the request's HTTP version.
pub fn headers(&self) -> &HeaderMap
[src]
Access the request's headers.
pub fn request(&self) -> &Request
[src]
Access the entire request.
pub fn app_data(&self) -> &AppData
[src]
Access app-global data.
pub fn param<T: FromStr>(&self, key: &str) -> Result<T, T::Err>
[src]
Extract and parse a route parameter by name.
Returns the results of parsing the parameter according to the inferred
output type T
.
The name should not include the leading :
or the trailing *
(if
any).
Errors
Yields an Err
if the parameter was found but failed to parse as an
instance of type T
.
Panics
Panic if key
is not a parameter for the route.
pub async fn body_bytes<'_>(&'_ mut self) -> Result<Vec<u8>>
[src]
Reads the entire request body into a byte buffer.
This method can be called after the body has already been read, but will produce an empty buffer.
Errors
Any I/O error encountered while reading the body is immediately returned
as an Err
.
pub async fn body_string<'_>(&'_ mut self) -> Result<String>
[src]
Reads the entire request body into a string.
This method can be called after the body has already been read, but will produce an empty buffer.
Errors
Any I/O error encountered while reading the body is immediately returned
as an Err
.
If the body cannot be interpreted as valid UTF-8, an Err
is returned.
pub async fn body_json<T: DeserializeOwned, '_>(&'_ mut self) -> Result<T>
[src]
Reads and deserialized the entire request body via json.
Errors
Any I/O error encountered while reading the body is immediately returned
as an Err
.
If the body cannot be interpreted as valid json for the target type T
,
an Err
is returned.
pub fn take_body(&mut self) -> Body
[src]
Remove ownership of the request body, replacing it with an empty body.
Used primarily for working directly with the body stream.
pub fn extensions(&self) -> &Extensions
[src]
Access the extensions to the context.
pub fn extensions_mut(&mut self) -> &mut Extensions
[src]
Mutably access the extensions to the context.
Trait Implementations
impl<AppData> CookiesExt for Context<AppData>
[src]
fn get_cookie(
&mut self,
name: &str
) -> Result<Option<Cookie<'static>>, StringError>
[src]
&mut self,
name: &str
) -> Result<Option<Cookie<'static>>, StringError>
fn set_cookie(&mut self, cookie: Cookie<'static>) -> Result<(), StringError>
[src]
fn remove_cookie(&mut self, cookie: Cookie<'static>) -> Result<(), StringError>
[src]
impl<AppData: Send + Sync + 'static> ExtractForms for Context<AppData>
[src]
fn body_form<T: DeserializeOwned>(
&mut self
) -> Pin<Box<dyn Future<Output = EndpointResult<T>> + Send + 'static>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = EndpointResult<T>> + Send + 'static>>
fn body_multipart(
&mut self
) -> Pin<Box<dyn Future<Output = EndpointResult<Multipart<Cursor<Vec<u8>>>>> + Send + 'static>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = EndpointResult<Multipart<Cursor<Vec<u8>>>>> + Send + 'static>>
impl<'de, Data> ExtractQuery<'de> for Context<Data>
[src]
fn url_query<T: Deserialize<'de>>(&'de self) -> Result<T, Error>
[src]
Auto Trait Implementations
impl<AppData> Send for Context<AppData> where
AppData: Send + Sync,
AppData: Send + Sync,
impl<AppData> !Sync for Context<AppData>
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,