logo
pub trait Endpoint: Send + Sync {
    fn call<'life0, 'life1, 'async_trait>(
        &'life0 self,
        ctx: &'life1 mut Context
    ) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
; }
Expand description

An HTTP request handler.

This trait is automatically implemented for Fn types, and so is rarely implemented directly by Envoy users.

In practice, endpoints are functions that take a Request as an argument and return a type T that implements Into<Response>.

Endpoints are implemented as asynchronous functions that make use of language features currently only available in Rust Nightly. For this reason, we have to explicitly enable the attribute will be omitted in most of the documentation.

A simple endpoint that is invoked on a GET request and returns a String:

async fn hello(ctx: &mut envoy::Context) -> envoy::Result {
    Ok(ctx.res.set_body(String::from("hello")))
}

let mut app = envoy::Server::new();
app.at("/hello").get(hello);

Required Methods

Invoke the endpoint within the given context

Trait Implementations

Formats the value using the given formatter. Read more

Invoke the endpoint within the given context

Implementations on Foreign Types

Implementors