hello
The simplest example demonstrating a basic HTTP server with a single route.
Source Code
Path: examples/hello/
const std = @import("std");
const tk = @import("tokamak");
const routes: []const tk.Route = &.{
.get("/", hello),
};
fn hello() ![]const u8 {
return "Hello, world!";
}
pub fn main(init: std.process.Init) !void {
var server = try tk.Server.init(init.io, init.gpa, routes, .{});
defer server.deinit();
try server.start();
}
The Handler
The handler function simply returns a string:
fn hello() ![]const u8 {
return "Hello, world!";
}
Features Demonstrated
- Basic server setup
- Simple routing
- Handler functions
- Manual memory management with GeneralPurposeAllocator
Running
cd examples/hello
zig build run
The server will start on the default port (8080). Visit http://localhost:8080/ to see the greeting.