Skip to content
/ zinc Public

Zinc is a high performance framework written in pure Zig. Zinc focuses on hight-performance, usability, security, and extensibility.

License

Notifications You must be signed in to change notification settings

zon-dev/zinc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zinc


Zinc is a high-performance web framework written in Zig(Ziglang).

Usage.

const z = @import("zinc");

pub fn main() !void {
    var zinc = try z.init(.{ .port = 8080 });

    var router = zinc.getRouter();
    try router.get("/", helloWorld);
    try router.add(&.{ .GET, .POST }, "/ping", pong);

    var catchers = zinc.getCatchers();
    try catchers.put(.not_found, notFound);

    try zinc.run();
}

fn pong(ctx: *z.Context, _: *z.Request, _: *z.Response) anyerror!void {
    try ctx.Text(.{}, "pong!");
}

fn helloWorld(ctx: *z.Context, _: *z.Request, _: *z.Response) anyerror!void {
    try ctx.JSON(.{}, .{ .message = "Hello, World!" });
}

// Default 404 (not found) page
fn notFound(ctx: *z.Context, _: *z.Request, _: *z.Response) anyerror!void {
    try ctx.HTML(.{
        .status = .not_found,
    }, "<h1>404 Not Found</h1>");
}