Struct shs::Request

source ·
pub struct Request { /* private fields */ }
Expand description

Requirements for the Server Error type parameter. 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§

source§

impl Request

source

pub fn url(&self) -> &Url

Get the request URL.

source

pub fn headers(&self) -> &HashMap<UniCase<String>, String>

Get the request headers.

source

pub fn read_json<'a, D: Deserialize<'a>>(&'a self) -> Result<D, Error>

Deserialize the body as JSON.

source

pub fn write_bytes(&mut self, body: &[u8])

Write the input as the response body. This also sets the Content-Type to application/octet-stream.

source

pub fn write_json<S: Serialize>(&mut self, body: &S) -> Result<(), Error>

Serialize the input as the response body. This also sets the Content-Type to application/json.

source

pub fn write_text(&mut self, body: &str)

Write the input as the response body with utf-8 encoding. This also sets the Content-Type to text/plain; charset=UTF-8.

source

pub fn set_status(&mut self, status: StatusCode)

Set the response status code.

source

pub fn set_not_found(&mut self)

Set the response status code to 404 (not found).

source

pub fn set_header(&mut self, name: &str, value: &str)

Set a response header.

source

pub fn set_content_type(&mut self, value: &str)

Set the Content-Type response header.

source

pub fn path_param<F>(&self, name: &str) -> Result<F, Error>
where 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.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.