Trait wasm_framework::Handler[][src]

pub trait Handler {
#[must_use]    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
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
; }

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

#[must_use]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
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

Implementation of application request handler

Loading content...

Implementors

Loading content...