Endpoint

Trait Endpoint 

Source
pub trait Endpoint: Send + Sync {
    // Required method
    fn call<'life0, 'life1, 'async_trait>(
        &'life0 self,
        ctx: &'life1 mut Context,
    ) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: '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§

Source

fn call<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 mut Context, ) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Invoke the endpoint within the given context

Trait Implementations§

Source§

impl Debug for dyn Endpoint

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Endpoint for Box<dyn Endpoint>

Source§

fn call<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 mut Context, ) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Invoke the endpoint within the given context

Implementations on Foreign Types§

Source§

impl Endpoint for Box<dyn Endpoint>

Source§

fn call<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 mut Context, ) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Implementors§

Source§

impl Endpoint for Server

Source§

impl<F> Endpoint for F
where F: for<'a1> Fn1<&'a1 mut Context> + Sync + Send, for<'a1> <F as Fn1<&'a1 mut Context>>::Output: Future<Output = Result> + Send,