[−][src]Struct shs::Request
Request type passed to handlers. It provides both the input request and the output response, as well as access to state shared across requests.
Implementations
impl<T: Send + Sync> Request<T>
[src]
pub fn url(&self) -> &Url
[src]
Get the request URL.
pub fn headers(&self) -> &HashMap<UniCase<String>, String>
[src]
Get the request headers.
pub fn read_json<'a, D: Deserialize<'a>>(&'a self) -> Result<D, Error>
[src]
Deserialize the body as JSON.
pub fn write_bytes(&mut self, body: &[u8])
[src]
Write the input as the response body. This also sets the
Content-Type
to application/octet-stream
.
pub fn write_json<S: Serialize>(&mut self, body: &S) -> Result<(), Error>
[src]
Serialize the input as the response body. This also sets the
Content-Type
to application/json
.
pub fn write_text(&mut self, body: &str)
[src]
Write the input as the response body with utf-8 encoding. This
also sets the Content-Type
to text/plain; charset=UTF-8
.
pub fn set_status(&mut self, status: StatusCode)
[src]
Set the response status code.
pub fn set_not_found(&mut self)
[src]
Set the response status code to 404 (not found).
pub fn set_header(&mut self, name: &str, value: &str)
[src]
Set a response header.
pub fn set_content_type(&mut self, value: &str)
[src]
Set the Content-Type
response header.
pub fn path_param<F>(&self, name: &str) -> Result<F, Error> where
F::Err: Error + Send + Sync + 'static,
F: FromStr,
[src]
F::Err: Error + Send + Sync + 'static,
F: FromStr,
Get a path parameter. For example, if an input route
"/resource/:key" is defined, the handler can get the ":key"
portion by calling path_param("key")
. The returned type can
be anything that implements FromStr
.
pub fn with_state<R, F>(&self, f: F) -> Result<R, Error> where
F: Fn(&T) -> R,
[src]
F: Fn(&T) -> R,
Access shared state via a closure.
pub fn with_state_mut<R, F>(&self, f: F) -> Result<R, Error> where
F: Fn(&mut T) -> R,
[src]
F: Fn(&mut T) -> R,
Modify shared state via a closure.
Auto Trait Implementations
impl<T> RefUnwindSafe for Request<T>
impl<T> Send for Request<T> where
T: Send + Sync,
T: Send + Sync,
impl<T> Sync for Request<T> where
T: Send + Sync,
T: Send + Sync,
impl<T> Unpin for Request<T>
impl<T> UnwindSafe for Request<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> 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<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,