Crate maker_web

Crate maker_web 

Source
Expand description

maker_web - High-performance, zero-allocation HTTP server for microservices

A performance-oriented HTTP server with comprehensive configuration for memory management, connection handling, and protocol support. Designed for microservices requiring fine-grained control over resources.

§Protocol Support

§Performance Characteristics

  • Zero-allocation pipeline - no heap allocations during request/response processing
  • Async/await ready - built on Tokio for scalable I/O and high concurrency
  • Pre-calculated buffers - fixed memory allocation per connection based on configured limits
  • Connection reuse - efficient keep-alive and connection pooling
  • Configurable timeouts - precise control over connection lifetimes and I/O operations
  • Multi-protocol optimization - HTTP/1.1, HTTP/1.0, and HTTP/0.9+ for various performance needs

§Examples

Quick start:

use maker_web::{Server, Handler, Request, Response, Handled, StatusCode};
use tokio::net::TcpListener;

struct MyHandler;

impl Handler<()> for MyHandler {
    async fn handle(&self, _: &mut (), _: &Request, resp: &mut Response) -> Handled {
        resp.status(StatusCode::Ok).body("Hello World!")
    }
}

#[tokio::main]
async fn main() {
    Server::builder()
        .listener(TcpListener::bind("127.0.0.1:8080").await.unwrap())
        .handler(MyHandler)
        .build()
        .launch()
        .await;
}

Something in between :) :

use maker_web::{Handled, Handler, Request, Response, Server, StatusCode};
use tokio::net::TcpListener;
 
struct MyHandler;
 
impl Handler<()> for MyHandler {
    async fn handle(&self, _: &mut (), req: &Request, resp: &mut Response) -> Handled {
        match req.url().path_segments() {
            [b"api", user, b"name"] => {
                resp.status(StatusCode::Ok).body(user)
            }
            [b"api", user, b"name", b"len"] => {
                resp.status(StatusCode::Ok).body(user.len())
            }
            [b"api", b"echo", text] => {
                resp.status(StatusCode::Ok).body(text)
            }
            _ => resp.status(StatusCode::NotFound).body("qwe"),
        }
    }
}
 
#[tokio::main]
async fn main() {
    Server::builder()
        .listener(TcpListener::bind("127.0.0.1:8080").await.unwrap())
        .handler(MyHandler)
        .build()
        .launch()
        .await;
}

Advanced configuration:

use maker_web::{Server, limits::{ConnLimits, ReqLimits, ServerLimits}};
use tokio::net::TcpListener;
use std::time::Duration;

#[tokio::main]
async fn main() {
    Server::builder()
        .listener(TcpListener::bind("127.0.0.1:8080").await.unwrap())
        .handler(MyHandler)
        .server_limits(ServerLimits {
            max_connections: 5000, // Higher concurrency
            ..ServerLimits::default()
        })
        .connection_limits(ConnLimits {
            socket_read_timeout: Duration::from_secs(5),
            max_requests_per_connection: 10_000,
            ..ConnLimits::default()
        })
        .request_limits(ReqLimits {
            header_count: 18,      // More headers for complex APIs
            body_size: 16 * 1024,  // 16KB for larger payloads
            ..ReqLimits::default()
        })
        .build()
        .launch()
        .await;
}

§Use Cases

  • High-throughput microservices - configurable for specific workloads
  • Resource-constrained environments - predictable memory usage
  • Internal APIs - security-conscious defaults
  • Performance-critical applications - zero-allocation design
  • Legacy system integration - HTTP/1.0 compatibility

Modules§

limits
Web server configuration limits and timeouts
query
Zero-copy URL query string parser with flexible collection support.

Structs§

BodyWriter
Writer for constructing the HTTP response body. Used in body_with.
Request
High-performance HTTP request representation.
Response
HTTP response builder for constructing server responses.
Server
An HTTP server that processes incoming connections and requests.
ServerBuilder
Builder for configuring and creating Server instances.
Url
A parsed URL representation optimized for HTTP request handling.

Enums§

Method
HTTP request methods
StatusCode
HTTP status codes
Version
HTTP protocol version

Traits§

ConnectionData
Managing user session data stored between requests within a single HTTP connection.
Handler
A trait for handling HTTP requests and generating responses.
WriteBuffer
Trait for writing data to the Response buffer.