Over the last few months a lot of my spare time has been spent working on a new MIT-licensed web framework (Jetzig) and templating language (Zmpl) for Zig.
The project is written in 100% Zig and (currently) has no external dependencies. This may change in future but the current intention is to support the growth of the Zig stdlib and to remain as portable as possible. A major goal for the project is also to stay up-to-date and always be compatible with the latest official Zig release.
Jetzig aims to provide a rich set of user-friendly tools for building modern web applications quickly. While Zap compares itself to Python's Flask microframework, Jetzig is intended to be a "batteries-included" framework similar to Ruby on Rails. Jetzig works great with HTMX.
Here's a quick example of a view. Simply creating this file creates a new JSON route:
// src/app/views/index.zig
pub fn index(request: *jetzig.http.Request, data: *jetzig.data.Data) anyerror!jetzig.views.View {
var object = try data.object();
try object.put("message", data.string("Welcome to Jetzig!"));
return request.render(.ok);
}
Creating a matching .zmpl
file creates an HTML route:
// src/app/views/index.zmpl
if (std.crypto.random.int(u1) == 1) {
<div>{.message}</div>
} else {
<div>No message for you today!</div>
}
The documentation page listed below provides a quick-start guide if you want to run locally, and the homepage has some examples showing how things fit together. If you are interested in hearing more about this project please let me know and I will do further updates as I make progress.
This project is still very early on in development but I have made enough progress with key features like templating, encrypted user sessions, JSON data creation, etc. that I thought it would be good to share a preview with the community.
Currently Jetzig works with Zig 0.11. I will begin a new branch for 0.12 support soon.
Links:
- Project Homepage
- Documentation (very much a work in progress) [edit: fix broken URL]
- Jetzig Github
- Zmpl Github
Latest comments (1)
Awesome to see more work happening in this space!
I'm especially happy to see more templating languages pop up. I'm working on my own take on this, but for static websites.
If you haven't done so already, consider joining the Software You Can Love Discord server, I've posted this article there as well and I think there might be there a handful of people who might be interested in more templating language discussion.