Skip to main content

HttpServer

Trait HttpServer 

Source
pub trait HttpServer: Send + Sync {
    // Required methods
    fn start<'life0, 'life1, 'async_trait>(
        &'life0 self,
        config: &'life1 ServerConfig,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn stop<'life0, 'async_trait>(
        &'life0 self,
        timeout: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn is_running(&self) -> bool;
    fn address(&self) -> Option<SocketAddr>;
    fn register_handler(
        &mut self,
        path: &str,
        method: HttpMethod,
        handler: Box<dyn RequestHandler>,
    );
    fn register_middleware(&mut self, middleware: Box<dyn Middleware>);
    fn get_metrics(&self) -> ServerMetrics;
    fn health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = HealthStatus> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Main HTTP server trait

Required Methods§

Source

fn start<'life0, 'life1, 'async_trait>( &'life0 self, config: &'life1 ServerConfig, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Start the server

Source

fn stop<'life0, 'async_trait>( &'life0 self, timeout: Duration, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stop the server gracefully

Source

fn is_running(&self) -> bool

Check if server is running

Source

fn address(&self) -> Option<SocketAddr>

Get server address

Source

fn register_handler( &mut self, path: &str, method: HttpMethod, handler: Box<dyn RequestHandler>, )

Register a request handler

Source

fn register_middleware(&mut self, middleware: Box<dyn Middleware>)

Register middleware

Source

fn get_metrics(&self) -> ServerMetrics

Get server metrics

Source

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = HealthStatus> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Health check

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§