Skip to main content

Module server

Module server 

Source
Expand description

Reusable HTTP runtime and service boundary.

This module provides a transport-owning HTTP runtime that downstream Rust projects can embed without importing internal modules or depending directly on Hyper.

§Architecture

let server = Server::builder()
    .runtime(RuntimeConfig::default())
    .build()?;
let handle = server.start_with_service(my_service).await?;

handle.ready().await?;
// server is accepting connections

handle.shutdown();
// server drains and stops
handle.wait().await?;

The runtime owns:

  • Listener acceptance
  • HTTP/1 parsing
  • Request conversion to canonical types
  • Response normalization
  • Timeout enforcement
  • Connection and file-stream permits
  • Connection/task tracking
  • Graceful shutdown with drain deadline
  • Forced shutdown with task cancellation

Services own:

  • Request handling logic
  • Response construction

§Public types

Re-exports§

pub use crate::primitives::request::Request;
pub use config::try_from_serve_config;
pub use config::RuntimeConfig;
pub use config::RuntimeConfigBuilder;
pub use errors::ServerError;
pub use errors::ShutdownResult;
pub use handle::ServerHandle;
pub use lifecycle::LifecycleState;
pub use service::service_fn;
pub use service::service_fn_head;
pub use service::service_fn_with_policy;
pub use service::Service;
pub use service::ServiceError;
pub use service::ServiceFn;
pub use static_service::StaticService;
pub use static_service::StaticServiceBuilder;

Modules§

config
Runtime configuration for the HTTP server.
connection
Connection execution pipeline.
errors
Public runtime error types.
handle
Server lifecycle handle.
lifecycle
Lifecycle state machine for the HTTP server.
service
Transport-independent service abstraction.
static_service
Canonical, confined static-file service.

Structs§

RuntimeState
Transport state shared by every connection in one running server.
Server
A reusable HTTP runtime server.
ServerBuilder
Builder for constructing a Server.