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.
- 🚀 Multi-threaded HTTP server with automatic CPU core detection
- 🔌 WebSocket support with automatic upgrade handling
- 💪 Keep-alive connection support for improved performance
- 🔄 Integration with SPICE for parallel computing tasks
- 📊 Built-in benchmarking tools
- 🧪 Comprehensive test suite
- Ensure you have Zig 0.11.0 or later installed
- Clone the repository:
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 tool
Start 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:
- Multi-threaded architecture utilizing all available CPU cores
- Keep-alive connection support
- Efficient WebSocket implementation
- Integration with SPICE for parallel computing tasks
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.