High-Performance Async HTTP Framework for Zig

Built on top of libxev for maximum performance and scalability. Features advanced routing, middleware support, and comprehensive built-in protection.

main.zig
const std = @import("std");
const libxev_http = @import("libxev-http");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    // Create HTTP server
    var server = try libxev_http.createServer(
        allocator, "127.0.0.1", 8080
    );
    defer server.deinit();

    // Add middleware
    try server.use("logging", libxev_http.loggingMiddleware);
    try server.use("cors", libxev_http.corsMiddleware);

    // Set up routes
    _ = try server.get("/", indexHandler);
    _ = try server.get("/api/status", statusHandler);
    _ = try server.get("/users/:id", userHandler);

    // Start listening
    try server.listen();
}

fn indexHandler(ctx: *libxev_http.Context) !void {
    try ctx.html("<h1>Hello, libxev-http!</h1>");
}

Why Choose libxev-http?

⚔

Async Event-Driven

Built on libxev for maximum performance and scalability across all platforms

šŸ›£ļø

Advanced Routing

Parameter extraction, wildcards, and flexible middleware support

šŸ”§

Flexible Middleware

Global and route-specific middleware with built-in common functionality

šŸ›”ļø

Built-in Protection

Comprehensive timeout protection and request validation

āš™ļø

Flexible Configuration

Multiple preset configurations for different environments

šŸ”’

Memory Safe

Comprehensive resource management and security validation

šŸŒ

Cross-Platform

Supports Linux (io_uring/epoll), macOS (kqueue), and Windows (IOCP)

šŸ“¦

Production Ready

Battle-tested HTTP parsing and response building

Quick Start

1

Installation

Add libxev-http to your project using git submodules:

git submodule add https://github.com/mitchellh/libxev.git libxev
2

Try Examples

Run the example server to see libxev-http in action:

# Clone and run
git clone <repository-url>
cd libxev-http
zig build run-basic
3

Build Your Server

Create your first HTTP server with middleware and routing:

const server = try libxev_http.createServer(allocator, "127.0.0.1", 8080);
try server.use("logging", libxev_http.loggingMiddleware);
_ = try server.get("/", indexHandler);
try server.listen();

Performance & Architecture

High Performance

  • Async I/O built on libxev's efficient event loop
  • Zero-copy parsing with minimal memory allocations
  • Efficient connection management and pooling
  • Cross-platform optimized I/O mechanisms

Modular Architecture

  • lib.zig - Main server implementation
  • router.zig - High-performance routing
  • middleware.zig - Flexible middleware system
  • security.zig - Timeout protection