zon-dev/zinc
Zinc is a web framework written in pure Zig with a focus on high performance, usability, security, and extensibility.
refs
refs
Zinc is a high-performance web framework written in pure Zig with a focus on usability, security, and extensibility. It features asynchronous I/O powered by the aio library for maximum performance across all supported platforms.
:rocket: Now with async I/O support via aio library for fast performance!
:construction: It's still in active development. Not the fastest zig framework in the universe, but fast enough.
:warning: Do not use it in production environments until the stable release.
Zinc uses a modern async/await architecture with the aio library:
Add zinc to your build.zig.zon
:
zig fetch --save https://github.com/zon-dev/zinc/archive/refs/heads/main.zip
A basic example with async I/O:
const zinc = @import("zinc");
pub fn main() !void {
var z = try zinc.init(.{
.port = 8080,
.num_threads = 4, // Configure thread pool
.force_nonblocking = true, // Enable async I/O
});
defer z.deinit();
var router = z.getRouter();
try router.get("/", helloWorld);
try z.run();
}
fn helloWorld(ctx: *zinc.Context) anyerror!void {
try ctx.text("Hello world!", .{});
}
var router = z.getRouter();
var api = try router.group("/api");
try api.get("/users", getUsers);
try api.post("/users", createUser);
var v1 = try api.group("/v1");
try v1.get("/status", getStatus);
// Global middleware
try router.use(&.{authMiddleware, corsMiddleware});
// Route-specific middleware
try router.get("/protected", protectedHandler);
// Serve static files
try router.staticFile("/favicon.ico", "public/favicon.ico");
// Serve static directories
try router.staticDir("/assets", "public/assets");
var z = try zinc.init(.{
.port = 8080,
.num_threads = 8, // Worker threads
.read_buffer_len = 8192, // Read buffer size
.force_nonblocking = true, // Enable async I/O
.stack_size = 1048576, // Thread stack size
});
Zinc with aio integration provides:
Run the comprehensive test suite:
zig build test
All tests pass with zero memory leaks and full async I/O coverage.
git clone https://github.com/zon-dev/zinc.git
cd zinc
zig build
zig build test
We welcome contributions! Please see our contributing guidelines for details.
This project is licensed under the MIT License - see the LICENSE file for details.
:star: Star this repository if you find it useful!