⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

httpx.zig is a production-ready, high-performance HTTP client and server library for Zig, designed for building modern, robust, and scalable networked applications.

License

Notifications You must be signed in to change notification settings

zigcc/httpx.zig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

httpx.zig

This is a fork of https://github.com/muhammad-fiaz/httpx.zig !

httpx.zig is a production-ready, high-performance HTTP server library for the Zig programming language, designed for building modern, robust, and scalable networked applications.


Features

  • Comprehensive HTTP Support: Full implementation of HTTP/1.1, HTTP/2, and experimental HTTP/3.
  • WebSocket Server: Full-featured WebSocket support (RFC 6455).
  • Asynchronous Core: Built for high-concurrency and non-blocking I/O.
  • TLS/SSL: Integrated TLS support for secure connections.
  • Extensible: Support for middleware to customize request/response handling.
  • Modern Zig API: Designed with a focus on clarity, safety, and performance.

Installation

To add httpx.zig to your project, add it as a dependency in your build.zig.zon file:

.{
    .name = "my-project",
    .version = "0.1.0",
    .dependencies = .{
        .httpx = .{
            .url = "https://github.com/zigcc/httpx.zig/archive/main.tar.gz",
            .hash = "<hash_of_the_tarball>", // Replace with the actual hash
        },
    },
}

Then, in your build.zig, add the dependency to your executable:

const httpx_dep = b.dependency("httpx", .{});
const httpx_module = httpx_dep.module("httpx");
exe.addModule("httpx", httpx_module);

Quick Start

Here is a simple example of creating an HTTP server:

const std = @import("std");
const httpx = @import("httpx");

fn handleHello(ctx: *httpx.Context) !void {
    try ctx.json(.{ .message = "Hello, World!" }, .{});
}

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

    var server = try httpx.Server.init(allocator, .{ .port = 8080 });
    defer server.deinit();

    try server.get("/hello", handleHello);

    std.debug.print("Server listening on http://localhost:8080\n", .{});
    try server.listen();
}

API Overview

The library is structured into several key components:

  • httpx.Server: A server for handling incoming HTTP connections.
  • httpx.Request: Represents an HTTP request.
  • httpx.Response: Represents an HTTP response.
  • httpx.Router: A flexible router for mapping paths to handlers in the server.
  • httpx.WebSocketConnection: Server-side WebSocket connection handler.

License

MIT License - see LICENSE for details.

About

httpx.zig is a production-ready, high-performance HTTP client and server library for Zig, designed for building modern, robust, and scalable networked applications.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages