openSVM/zup
zig api server
A high-performance HTTP and WebSocket server framework written in Zig, designed for building scalable web applications with built-in parallel computing capabilities via SPICE integration.
git clone https://github.com/yourusername/zup.git
cd zup
Build the project using Zig's build system:
zig build
This will create the following executables in zig-out/bin/
:
server
: The main server executableexample-server
: An example server implementationbenchmark
: Benchmarking toolStart the server on localhost:8080:
zig build run
Or run directly:
./zig-out/bin/server
Run the example server implementation:
zig build example
Run the test suite:
zig build test
Run framework-specific tests:
zig build test-framework
Run HTTP benchmarks:
zig build bench
The core server provides a simple interface for handling HTTP requests:
const std = @import("std");
const Server = @import("main.zig").Server;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const address = try std.net.Address.parseIp("127.0.0.1", 8080);
var server = try Server.init(allocator, address);
defer server.deinit();
try server.start();
}
The server automatically handles WebSocket upgrades and provides a simple message-based API:
// WebSocket frame handling example
const ws = @import("websocket.zig");
// Echo server implementation
while (true) {
const frame = try ws.readMessage(stream);
defer allocator.free(frame.payload);
switch (frame.opcode) {
.text, .binary => try ws.writeMessage(stream, frame.payload),
.close => break,
else => {},
}
}
The framework module provides additional utilities for building web applications:
const framework = @import("framework");
// Initialize router
var router = try framework.Router.init(allocator);
defer router.deinit();
// Add routes
try router.get("/", handleRoot);
try router.post("/api/data", handleData);
The server is designed for high performance:
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.