Simple, concise view functions
const std = @import("std");
const jetzig = @import("jetzig");
pub const layout = "application";
pub fn index(request: *jetzig.Request) !jetzig.View {
var object = try request.data(.object);
try object.put("url", "https://jetzig.dev/");
try object.put("title", "Jetzig Website");
try object.put("message", "Welcome to Jetzig!");
return request.render(.ok);
}
JSON by default on all endpoints
$ curl http://localhost:8080/example.json
{
"url": "https://jetzig.dev/",
"message": "Welcome to Jetzig!",
"title": "Jetzig Website"
}
Live Example (JSON)
Live Example (HTML)
Easy email delivery with content templating
pub fn post(request: *jetzig.Request) !jetzig.View {
var root = try request.data(.object);
const params = try request.params();
// Set mail template params.
try root.put("from", params.get("from"));
try root.put("message", params.get("message"));
// Create email.
const mail = request.mail("contact", .{ .to = &.{"hello@jetzig.dev"} });
// Deliver asynchronously.
try mail.deliver(.background, .{});
return request.render(.created);
}
Modal templating with partials, Markdown, and Zig
<html>
<body>
@partial header
@markdown {
# {{.message}}
[{{.title}}]({{.url}})
}
@zig {
if (10 > 1) {
<span>10 is greater than 1!</span>
}
}
<p>{{.message}}</p>
@partial link(href: .url, title: .title)
@partial footer
</body>
</html>
Readable development logs