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§
Sourcefn 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 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
Sourcefn 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 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
Sourcefn is_running(&self) -> bool
fn is_running(&self) -> bool
Check if server is running
Sourcefn address(&self) -> Option<SocketAddr>
fn address(&self) -> Option<SocketAddr>
Get server address
Sourcefn register_handler(
&mut self,
path: &str,
method: HttpMethod,
handler: Box<dyn RequestHandler>,
)
fn register_handler( &mut self, path: &str, method: HttpMethod, handler: Box<dyn RequestHandler>, )
Register a request handler
Sourcefn register_middleware(&mut self, middleware: Box<dyn Middleware>)
fn register_middleware(&mut self, middleware: Box<dyn Middleware>)
Register middleware
Sourcefn get_metrics(&self) -> ServerMetrics
fn get_metrics(&self) -> ServerMetrics
Get server metrics
Sourcefn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = HealthStatus> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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".