Hyperlane: Unleash the Power of Rust for High-Performance Web Services

In the fast-evolving world of web development, performance, flexibility, and ease of use are non-negotiable. Enter Hyperlane, a lightweight, high-performance HTTP server library crafted in Rust, designed to simplify and supercharge your network service development. Whether you're building modern APIs, real-time applications, or cross-platform services, Hyperlane delivers the tools you need with elegance and efficiency. Let’s dive into what makes Hyperlane a standout choice, explore its features, and see it in action with real code and performance data. What is Hyperlane? Hyperlane is a Rust-based HTTP server library that blends simplicity with power. It handles the essentials—HTTP request parsing, response construction, and TCP communication—while offering advanced features like middleware, WebSocket, and Server-Sent Events (SSE) support. Built entirely with pure Rust and its standard library, Hyperlane leverages the Tokio asynchronous runtime to deliver seamless, high-performance networking without platform-specific dependencies. Key Features That Shine Lightweight & Lightning Fast: Minimal overhead paired with exceptional performance, thanks to Rust and Tokio. Cross-Platform Mastery: Consistent APIs across Windows, Linux, and macOS—no compromises, no platform-specific hacks. Middleware Magic: Request and response middleware let you customize server behavior with ease. Real-Time Ready: Built-in WebSocket and SSE support for efficient, real-time communication. Pure Rust Power: No external dependencies beyond the Rust ecosystem, ensuring reliability and portability. Hyperlane is your go-to for crafting modern web services that demand speed, scalability, and flexibility. Getting Started with Hyperlane Installation Adding Hyperlane to your Rust project is a breeze. Simply run: cargo add hyperlane That’s it! You’re ready to build something extraordinary. Quick Start Resources New to Hyperlane? Check out these resources to hit the ground running: GitHub Quick Start Repo Quick Start Docs Clone the example project to explore: git clone https://github.com/ltpp-universe/hyperlane-quick-start.git Hyperlane in Action: A Hands-On Example Let’s see Hyperlane’s capabilities with a practical example. This code sets up a server with middleware, routes, and WebSocket support: use hyperlane::*; async fn request_middleware(ctx: Context) { let socket_addr: String = ctx.get_socket_addr_or_default_string().await; ctx.set_response_header(SERVER, HYPERLANE) .await .set_response_header(CONNECTION, CONNECTION_KEEP_ALIVE) .await .set_response_header(CONTENT_TYPE, content_type_charset(TEXT_PLAIN, UTF8)) .await .set_response_header(DATE, gmt()) .await .set_response_header("SocketAddr", socket_addr) .await; } async fn response_middleware(ctx: Context) { let _ = ctx.send().await; let request: String = ctx.get_request_string().await; let response: String = ctx.get_response_string().await; ctx.log_info(&request, log_handler) .await .log_info(&response, log_handler) .await; } async fn root_route(ctx: Context) { ctx.set_response_status_code(200) .await .set_response_body("Hello hyperlane => /") .await; } async fn websocket_route(ctx: Context) { let request_body: Vec = ctx.get_request_body().await; let _ = ctx.send_response_body(request_body).await; } #[tokio::main] async fn main() { let server: Server = Server::new(); server.host("0.0.0.0").await; server.port(60000).await; server.enable_nodelay().await; server.log_dir("./logs").await; server.enable_inner_log().await; server.enable_inner_print().await; server.log_size(100_024_000).await; server.http_line_buffer_size(4096).await; server.websocket_buffer_size(4096).await; server.request_middleware(request_middleware).await; server.response_middleware(response_middleware).await; server.route("/", root_route).await; server.route("/websocket", websocket_route).await; let test_string: String = "Hello hyperlane".to_owned(); server .route( "/test/:text", async_func!(test_string, |ctx| { let param: RouteParams = ctx.get_route_params().await; println_success!(format!("{:?}", param)); println_success!(test_string); panic!("Test panic"); }), ) .await; server.listen().await.unwrap(); } What’s Happening Here? Middleware: request_middleware adds custom headers, while response_middleware logs requests and responses. Routes: A root route (/) returns a greeting, and a WebSocket route (/websocket) echoes back data. Dynamic Routing: The /test/:text route demonstrates parameterized routes with error handling. Configuration: The ser

May 7, 2025 - 00:29
 0
Hyperlane: Unleash the Power of Rust for High-Performance Web Services

In the fast-evolving world of web development, performance, flexibility, and ease of use are non-negotiable. Enter Hyperlane, a lightweight, high-performance HTTP server library crafted in Rust, designed to simplify and supercharge your network service development. Whether you're building modern APIs, real-time applications, or cross-platform services, Hyperlane delivers the tools you need with elegance and efficiency. Let’s dive into what makes Hyperlane a standout choice, explore its features, and see it in action with real code and performance data.

What is Hyperlane?

Hyperlane is a Rust-based HTTP server library that blends simplicity with power. It handles the essentials—HTTP request parsing, response construction, and TCP communication—while offering advanced features like middleware, WebSocket, and Server-Sent Events (SSE) support. Built entirely with pure Rust and its standard library, Hyperlane leverages the Tokio asynchronous runtime to deliver seamless, high-performance networking without platform-specific dependencies.

Key Features That Shine

  • Lightweight & Lightning Fast: Minimal overhead paired with exceptional performance, thanks to Rust and Tokio.
  • Cross-Platform Mastery: Consistent APIs across Windows, Linux, and macOS—no compromises, no platform-specific hacks.
  • Middleware Magic: Request and response middleware let you customize server behavior with ease.
  • Real-Time Ready: Built-in WebSocket and SSE support for efficient, real-time communication.
  • Pure Rust Power: No external dependencies beyond the Rust ecosystem, ensuring reliability and portability.

Hyperlane is your go-to for crafting modern web services that demand speed, scalability, and flexibility.

Getting Started with Hyperlane

Installation

Adding Hyperlane to your Rust project is a breeze. Simply run:

cargo add hyperlane

That’s it! You’re ready to build something extraordinary.

Quick Start Resources

New to Hyperlane? Check out these resources to hit the ground running:

Clone the example project to explore:

git clone https://github.com/ltpp-universe/hyperlane-quick-start.git

Hyperlane in Action: A Hands-On Example

Let’s see Hyperlane’s capabilities with a practical example. This code sets up a server with middleware, routes, and WebSocket support:

use hyperlane::*;

async fn request_middleware(ctx: Context) {
    let socket_addr: String = ctx.get_socket_addr_or_default_string().await;
    ctx.set_response_header(SERVER, HYPERLANE)
        .await
        .set_response_header(CONNECTION, CONNECTION_KEEP_ALIVE)
        .await
        .set_response_header(CONTENT_TYPE, content_type_charset(TEXT_PLAIN, UTF8))
        .await
        .set_response_header(DATE, gmt())
        .await
        .set_response_header("SocketAddr", socket_addr)
        .await;
}

async fn response_middleware(ctx: Context) {
    let _ = ctx.send().await;
    let request: String = ctx.get_request_string().await;
    let response: String = ctx.get_response_string().await;
    ctx.log_info(&request, log_handler)
        .await
        .log_info(&response, log_handler)
        .await;
}

async fn root_route(ctx: Context) {
    ctx.set_response_status_code(200)
        .await
        .set_response_body("Hello hyperlane => /")
        .await;
}

async fn websocket_route(ctx: Context) {
    let request_body: Vec<u8> = ctx.get_request_body().await;
    let _ = ctx.send_response_body(request_body).await;
}

#[tokio::main]
async fn main() {
    let server: Server = Server::new();
    server.host("0.0.0.0").await;
    server.port(60000).await;
    server.enable_nodelay().await;
    server.log_dir("./logs").await;
    server.enable_inner_log().await;
    server.enable_inner_print().await;
    server.log_size(100_024_000).await;
    server.http_line_buffer_size(4096).await;
    server.websocket_buffer_size(4096).await;
    server.request_middleware(request_middleware).await;
    server.response_middleware(response_middleware).await;
    server.route("/", root_route).await;
    server.route("/websocket", websocket_route).await;
    let test_string: String = "Hello hyperlane".to_owned();
    server
        .route(
            "/test/:text",
            async_func!(test_string, |ctx| {
                let param: RouteParams = ctx.get_route_params().await;
                println_success!(format!("{:?}", param));
                println_success!(test_string);
                panic!("Test panic");
            }),
        )
        .await;
    server.listen().await.unwrap();
}

What’s Happening Here?

  • Middleware: request_middleware adds custom headers, while response_middleware logs requests and responses.
  • Routes: A root route (/) returns a greeting, and a WebSocket route (/websocket) echoes back data.
  • Dynamic Routing: The /test/:text route demonstrates parameterized routes with error handling.
  • Configuration: The server runs on port 60000, with logging and buffer settings tailored for performance.

This example showcases Hyperlane’s flexibility and ease of use in a real-world scenario.

Performance That Speaks for Itself

Hyperlane isn’t just feature-rich—it’s blazing fast. Here’s how it stacks up against other frameworks in rigorous benchmarks using wrk and ab.

wrk Benchmark

Command:

wrk -c360 -d60s http://127.0.0.1:60000/

Results (QPS):

  • Tokio: 340,130.92
  • Hyperlane: 324,323.71
  • Rocket: 298,945.31
  • Rust Std: 291,218.96
  • Gin: 242,570.16
  • Go Std: 234,178.93
  • Node Std: 139,412.13

ab Benchmark

Command:

ab -n 1000000 -c 1000 -r -k http://127.0.0.1:60000/

Results (QPS):

  • Tokio: 308,596.26
  • Hyperlane: 307,568.90
  • Rocket: 267,931.52
  • Rust Std: 260,514.56
  • Go Std: 226,550.34
  • Gin: 224,296.16
  • Node Std: 85,357.18

Latency Comparison

For 10,000 cumulative requests:

Scenario http-request Avg Time hyper Avg Time
TCP Failure 39µs 78µs
Hyperlane 100µs 150µs
Apache 300µs 2500µs

Hyperlane consistently delivers top-tier QPS and low latency, rivaling even Tokio itself and outperforming popular frameworks like Rocket, Gin, and Node.js.

Why Hyperlane Stands Out

  • Speed: Near-native performance with minimal overhead.
  • Simplicity: Intuitive APIs that get you productive fast.
  • Versatility: From basic APIs to real-time apps, Hyperlane adapts effortlessly.

Explore more performance data on the GitHub test repo.

Join the Hyperlane Community

License

Hyperlane is proudly open-source under the MIT License. See the license file for details.

Contribute

Love Hyperlane? Help make it better! Submit an issue or pull request on GitHub.

Get in Touch

Questions or ideas? Reach out to the author: [ltpp-universe root@ltpp.vip](mailto:root@ltpp.vip).

Ready to Build?

Hyperlane combines Rust’s power with web development finesse, offering a robust, high-performance solution for your next project. Check out the API Docs and start building today. With Hyperlane, the future of web services is fast, flexible, and yours to shape!