pub trait Handler {
// Required method
fn handle<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
req: &'life1 Request,
ctx: &'life2 mut Context,
) -> Pin<Box<dyn Future<Output = Result<(), HandlerReturn>> + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
}
Expand description
Trait that defines app/service’s request handler and router See rustwasm-service-template for a more complete example
use service_logging::{Severity::Verbose,log,Logger};
use wasm_service::{Context,Handler,HandlerReturn,Request};
use async_trait::async_trait;
struct MyHandler {}
#[async_trait(?Send)]
impl Handler for MyHandler {
/// Process incoming Request
async fn handle(&self, req: &Request, ctx: &mut Context) -> Result<(), HandlerReturn> {
// log all incoming requests
log!(ctx, Verbose, method: req.method(), url: req.url());
match (req.method(), req.url().path()) {
(GET, "/hello") => {
ctx.response().content_type("text/plain; charset=UTF-8").unwrap()
.text("Hello world!");
}
_ => {
ctx.response().status(404).text("Not Found");
}
}
Ok(())
}
}
Required Methods§
Sourcefn handle<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
req: &'life1 Request,
ctx: &'life2 mut Context,
) -> Pin<Box<dyn Future<Output = Result<(), HandlerReturn>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn handle<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
req: &'life1 Request,
ctx: &'life2 mut Context,
) -> Pin<Box<dyn Future<Output = Result<(), HandlerReturn>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Implementation of application request handler