ooyeku/ziggurat
A modern, lightweight HTTP server framework for Zig that prioritizes performance, safety, and developer experience.
A modern, lightweight HTTP server framework for Zig that prioritizes performance, safety, and developer experience.
const std = @import("std");
const ziggurat = @import("ziggurat");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
// Initialize logger
try ziggurat.logger.initGlobalLogger(allocator);
// Initialize metrics
try ziggurat.metrics.initGlobalMetrics(allocator, 1000); // Keep last 1000 requests
defer ziggurat.metrics.deinitGlobalMetrics();
var builder = ziggurat.ServerBuilder.init(allocator);
var server = try builder
.host("127.0.0.1")
.port(8080)
.readTimeout(5000)
.writeTimeout(5000)
.build();
defer server.deinit();
try server.get("/", handleRoot);
try server.start();
}
fn handleRoot(request: *ziggurat.request.Request) ziggurat.response.Response {
_ = request;
return ziggurat.text("Hello, World!");
}
To enable TLS/HTTPS in your server:
var server = try builder
.host("127.0.0.1")
.port(443)
.enableTls("path/to/cert.pem", "path/to/key.pem")
.build();
Todo API - A RESTful API example with JSON handling
zig build run-ex1
Static File Server - File serving with caching and security
zig build run-ex2
See Usage Guide for more details.
Contributions are welcome. Please submit pull requests following the project's code style and including appropriate tests.
This project is licensed under the MIT License. See the LICENSE file for details.