[−][src]Trait roa::Endpoint
Endpoint
An endpoint is a request handler.
Build-in endpoint
There are some build-in endpoints.
- Functional endpoint
A normal functional endpoint is an async function with signature:
async fn(&mut Context) -> Result
.
use roa_core::{App, Context, Result}; async fn endpoint(ctx: &mut Context) -> Result { Ok(()) } let app = App::new().end(endpoint);
- Ok endpoint
()
is an endpoint always return Ok(())
let app = roa_core::App::new().end(());
- Status endpoint
Status
is an endpoint always return Err(Status)
use roa_core::{App, status}; use roa_core::http::StatusCode; let app = App::new().end(status!(StatusCode::BAD_REQUEST));
- String endpoint
Write string to body.
use roa_core::App; let app = App::new().end("Hello, world"); // static slice let app = App::new().end("Hello, world".to_owned()); // string
- Redirect endpoint
Redirect to an uri.
use roa_core::App; use roa_core::http::Uri; let app = App::new().end("/target".parse::<Uri>().unwrap());
Custom endpoint
You can implement custom Endpoint
for your types.
use roa_core::{App, Endpoint, Context, Next, Result, async_trait}; use async_std::sync::Arc; use std::time::Instant; fn is_endpoint(endpoint: impl for<'a> Endpoint<'a>) { } struct Logger; #[async_trait(?Send)] impl <'a> Endpoint<'a> for Logger { async fn call(&'a self, ctx: &'a mut Context) -> Result { Ok(()) } } let app = App::new().end(Logger);
Required methods
#[must_use]fn call<'async_trait>(
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
Self: 'async_trait,
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
Self: 'async_trait,
Call this endpoint.
Implementations on Foreign Types
impl<'a, S> Endpoint<'a, S> for String
[src]
String endpoint.
fn call<'async_trait>(
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
String: 'async_trait,
[src]
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
String: 'async_trait,
impl<'a, S> Endpoint<'a, S> for ()
[src]
ok endpoint, always return Ok(())
fn call<'async_trait>(
&'a self,
_ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
(): 'async_trait,
[src]
&'a self,
_ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
(): 'async_trait,
impl<'a, S> Endpoint<'a, S> for &'static str
[src]
Static slice endpoint.
fn call<'async_trait>(
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
&'static str: 'async_trait,
[src]
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
&'static str: 'async_trait,
Implementors
impl<'a, F, S, Fut> Endpoint<'a, S> for Websocket<F, S, Fut> where
S: State,
F: 'static + Sync + Send + Fn(Context<S>, SocketStream) -> Fut,
Fut: 'static + Send + Future<Output = ()>,
[src]
S: State,
F: 'static + Sync + Send + Fn(Context<S>, SocketStream) -> Fut,
Fut: 'static + Send + Future<Output = ()>,
fn call<'async_trait>(
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
Self: 'async_trait,
[src]
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
Self: 'async_trait,
impl<'a, S> Endpoint<'a, S> for Uri
[src]
Redirect endpoint.
fn call<'async_trait>(
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
Uri: 'async_trait,
[src]
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
Uri: 'async_trait,
impl<'a, S> Endpoint<'a, S> for Dispatcher<S> where
S: 'static,
[src]
S: 'static,
fn call<'async_trait>(
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<()>> + 'async_trait>> where
'a: 'async_trait,
Self: 'async_trait,
[src]
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<()>> + 'async_trait>> where
'a: 'async_trait,
Self: 'async_trait,
impl<'a, S> Endpoint<'a, S> for RouteTable<S> where
S: 'static,
[src]
S: 'static,
fn call<'async_trait>(
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result> + 'async_trait>> where
'a: 'async_trait,
Self: 'async_trait,
[src]
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result> + 'async_trait>> where
'a: 'async_trait,
Self: 'async_trait,
impl<'a, S> Endpoint<'a, S> for Boxed<S> where
S: 'static,
[src]
S: 'static,
fn call<'async_trait>(
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
Boxed<S>: 'async_trait,
[src]
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
Boxed<S>: 'async_trait,
impl<'a, S> Endpoint<'a, S> for Status
[src]
status endpoint.
fn call<'async_trait>(
&'a self,
_ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
Status: 'async_trait,
[src]
&'a self,
_ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
Status: 'async_trait,
impl<'a, S, E> Endpoint<'a, S> for Guard<E> where
E: Endpoint<'a, S>,
[src]
E: Endpoint<'a, S>,
fn call<'async_trait>(
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result> + 'async_trait>> where
'a: 'async_trait,
Self: 'async_trait,
[src]
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result> + 'async_trait>> where
'a: 'async_trait,
Self: 'async_trait,
impl<'a, S, T, F> Endpoint<'a, S> for T where
F: 'a + Future<Output = Result<(), Status>>,
S: 'a,
T: 'static + Send + Sync + Fn(&'a mut Context<S>) -> F,
[src]
F: 'a + Future<Output = Result<(), Status>>,
S: 'a,
T: 'static + Send + Sync + Fn(&'a mut Context<S>) -> F,
fn call<'async_trait>(
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
T: 'async_trait,
[src]
&'a self,
ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Status>> + 'async_trait>> where
'a: 'async_trait,
T: 'async_trait,
impl<'a, S, T, U> Endpoint<'a, S> for Chain<T, U> where
T: for<'b> Middleware<'b, S>,
U: Endpoint<'a, S>,
[src]
T: for<'b> Middleware<'b, S>,
U: Endpoint<'a, S>,