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
impl Request
sourcepub fn read_json<'a, D: Deserialize<'a>>(&'a self) -> Result<D, Error>
pub fn read_json<'a, D: Deserialize<'a>>(&'a self) -> Result<D, Error>
Deserialize the body as JSON.
sourcepub fn write_bytes(&mut self, body: &[u8])
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
.
sourcepub fn write_json<S: Serialize>(&mut self, body: &S) -> Result<(), Error>
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
.
sourcepub fn write_text(&mut self, body: &str)
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
.
sourcepub fn set_status(&mut self, status: StatusCode)
pub fn set_status(&mut self, status: StatusCode)
Set the response status code.
sourcepub fn set_not_found(&mut self)
pub fn set_not_found(&mut self)
Set the response status code to 404 (not found).
sourcepub fn set_header(&mut self, name: &str, value: &str)
pub fn set_header(&mut self, name: &str, value: &str)
Set a response header.
sourcepub fn set_content_type(&mut self, value: &str)
pub fn set_content_type(&mut self, value: &str)
Set the Content-Type
response header.
sourcepub fn path_param<F>(&self, name: &str) -> Result<F, Error>
pub fn path_param<F>(&self, name: &str) -> Result<F, Error>
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
.