pub trait ContextExt {
    // Required methods
    fn params<'a>(&'a self) -> &'a Params;
    fn json<T: Serialize>(&mut self, body: &T) -> Result<(), Box<dyn Error>>;
    fn get_json<'life0, 'async_trait, T>(
        &'life0 mut self
    ) -> Pin<Box<dyn Future<Output = Result<T, Box<dyn Error>>> + Send + 'async_trait>>
       where T: 'async_trait + DeserializeOwned,
             Self: 'async_trait,
             'life0: 'async_trait;
    fn req_header<'a>(&'a self, header: &str) -> Option<&'a str>;
}

Required Methods§

source

fn params<'a>(&'a self) -> &'a Params

Get route params, e.g. /users/:id

source

fn json<T: Serialize>(&mut self, body: &T) -> Result<(), Box<dyn Error>>

Set the response as JSON.

This method both sets the Content-Type header as well as the body as JSON.

source

fn get_json<'life0, 'async_trait, T>( &'life0 mut self ) -> Pin<Box<dyn Future<Output = Result<T, Box<dyn Error>>> + Send + 'async_trait>>where T: 'async_trait + DeserializeOwned, Self: 'async_trait, 'life0: 'async_trait,

Gets the request body as JSON.

source

fn req_header<'a>(&'a self, header: &str) -> Option<&'a str>

Retrieves a header from the incoming request object.

Implementors§