Skip to content

Repository files navigation

Verse

A comfortable and powerful web framework, where your Zig code looks like Zig

constIndexHtml=Page("index.html");
fnindex(frame: *Frame) !void {
constgreeting=tryallocPrint(frame.alloc, "Hi, {s}!", .{"Mom"});
deferframe.alloc.free(greeting);
varpage=IndexHtml.init(.{
// .main_title = "TODO add better title!",
.message=greeting,
.features= &[_].{
.{ .feature="good" },
.{ .feature="fast" },
.{ .feature="simple" },
},
.reason= .{ .inner_text="Template generated at comptime" },
});
tryframe.sendPage(&page);
}
constroutes=Routes(&[_]Match{
GET("index.html", index),
});
pubfnmain() !void {
varsrv=Server.init(default_allocator, routes, .{ .mode= .{ .zwsgi= .{} });
srv.serve() catch|err|switch (err) {
else=>std.debug.print("Server Error: {}\n", .{err});
};
}

and your HTML, looks like HTML

<!DOCTYPE html><html><head><title><MainTitledefault="Verse Template" /></title></head><body><p><Message/></p><ul><ForFeatures><li><Feature/></li></For><WithReason><p><InnerText/></p></With></body></html>

Features

  • uWSGI Protocol
  • HTTP
  • Compiles complete site to a completely self contained binary
  • Built in comptime Template library
  • Zero dependencies

Goals

  • Write Software You Can Love
  • Follow the Zig Zen

See also: SOCIAL.md

How do I ...

There are a number of demos/sites in examples/ that can get you started quickly. But there are a number of intentionally omitted features. Most notably is any middleware API. Verse follows Zig Zen and has no hidden control flow. All middleware patterns break this rule. Even without it, Verse still does support all the important "pre-flight" or request setup steps. If your application needs a more complex request setup step, you can use a custom response builder. That builder has full control over both the request frame, and the call to the endpoint. If you absolutely need to inspect, or alter the response before it's returned to the client, and understand the downsides of doing so, You could implement your own middleware by replacing the Frame downstream writer with a local buffer, The called endpoint would write to that buffer.

About

ergonomic web framework using comptime typed html templates

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages