An asynchronous Rust web framework built on Tokio. Use it to serve HTTP APIs, WebSocket connections, and server-sent events with explicit control over the request and response lifecycle.
API documentation · Quick start · Example project · Benchmarks
Create a binary crate with a Rust toolchain that supports edition 2024, then
add the published hyperlane crate:
cargo new hello-hyperlane
cd hello-hyperlane
cargo add hyperlaneReplace src/main.rs with:
use hyperlane::{Context, Server, ServerConfig, ServerError, ServerHook, Status, Stream, tokio};
const ADDRESS: &str = "127.0.0.1:3000";
const ROOT_PATH: &str = "/";
const GREETING: &str = "Hello from Hyperlane!\n";
struct Hello;
impl ServerHook for Hello {
async fn new(_: &mut Stream, _: &mut Context) -> Self {
Self
}
#[hyperlane::send]
async fn handle(self, stream: &mut Stream, ctx: &mut Context) -> Status {
ctx.get_mut_response().set_body(GREETING);
Status::Reject
}
}
#[tokio::main]
async fn main() -> Result<(), Box<ServerError>> {
let mut config = ServerConfig::default();
config.set_address(ADDRESS);
let mut server = Server::default();
server.server_config(config).route::<Hello>(ROOT_PATH);
let control = server.run().await?;
println!("Listening on http://{ADDRESS}");
control.wait().await;
Ok(())
}Run cargo run, then request the route from another terminal:
curl -fsS http://127.0.0.1:3000/The response is Hello from Hyperlane!. #[hyperlane::send] sends the
response built by the hook; Status::Reject stops the remaining pipeline so
another handler does not send a second response.
| Area | Support |
|---|---|
| HTTP/1 | HTTP/1.0 and HTTP/1.1 over TCP, with optional TLS |
| HTTP/2 | Cleartext with prior knowledge, or TLS using ALPN |
| HTTP/3 | QUIC with TLS; a certificate and private key are required |
| Routing | Route parameters, middleware, and lifecycle hooks |
| Realtime | WebSocket, server-sent events, and raw TCP handling |
Select the wire protocol per listener with ServerConfig.
| Crates | Role |
|---|---|
hyperlane, hyperlane-core, hyperlane-macros |
Server API, routing, and procedural macros |
http-type, http-constant, http-compress |
HTTP types, constants, and compression |
http-request |
Synchronous and asynchronous HTTP client |
| WebSocket plugin, Logger plugin | Opt-in plugins |
hyperlane-cli, hyperlane-performance |
Project and benchmark tooling |
These notes describe the current checkout. For the behavior of an installed version, see its release notes and API documentation.
Request::matches_if_none_match(current_etag) checks If-None-Match for an
existing representation without allocating or cloning header values. Call it
explicitly after selecting the representation and its current ETag; requests
that do not call it follow the unchanged request pipeline.
The helper uses weak entity-tag comparison, including repeated header fields,
quoted tags containing commas, and a standalone *. Tag contents are
case-sensitive. Missing fields, malformed field values, and invalid current
ETags return false, even when an earlier list member matched.
This is a matching predicate, not an automatic cache or response middleware.
The caller handles precondition ordering and chooses 304 Not Modified for
GET/HEAD or 412 Precondition Failed for other methods when appropriate. It
must also construct a protocol-correct response; the helper does not clear a
body, change headers, or implement If-Match strong comparison.
The server accepts Transfer-Encoding: chunked. Handlers receive the decoded
bytes and a Content-Length for those bytes, not the wire framing fields.
Chunk extensions and trailers are consumed but not exposed to handlers.
The configured body limit applies to the decoded size.
When a request cannot be parsed or exceeds a configured limit, the server sends an empty error response by default. HTTP/1.x closes the connection after the response; HTTP/2 and HTTP/3 complete the request stream. Registered request-error hooks retain control of the response instead.
The performance workflow runs the Docker-based harness against a baseline and a candidate in the same measurement window. It covers HTTP/1.1, HTTP/2, and HTTP/3, with separate keep-alive and short-connection cases. Open a workflow run for its report and raw measurements.
Use GitHub Issues for bug reports and feature requests. For protocol bugs, include the Hyperlane version, the HTTP version, and a minimal reproduction. Before opening a pull request, run:
cargo fmt --all --check
cargo test --workspace --all-features
cargo clippy --workspace --all-features --all-targets -- -D warningsHyperlane is distributed under the MIT License.
