a small web framework bolted onto iwnet
Builds against zig 0.11.0-dev.1605+abc9530a8
git clone --recursive https://github.com/linuxy/coyote.git
To build:
- zig build iwnet
- zig build
Example:
conststd=@import("std");
constlog=std.log.scoped(.model);
constCoyote=@import("coyote");
constDb=Coyote.Db;
pubconstModels=@import("./models/export.zig"); //must be named Modelspubfnmain() !void {
varcoyote=tryCoyote.init();
defercoyote.deinit();
trycoyote.templates("examples/templates/");
trycoyote.database(.{.host="localhost",
.port=5434,
.user="test",
.pass="test",
.db="testdb"});
trycoyote.config(.{.listen="localhost",
.port=8080});
trycoyote.run();
}
pubconstcoyote_user=struct { //must have coyote_ prefixconstSelf=@This();
route: []constu8="/user",
template: []constu8="user.html",
flags: u32= (Coyote.Post|Coyote.Put|Coyote.Get),
handler: fn(req: Coyote.Request, data: Coyote.Data) u32=handler,
pubfnhandler(req: Coyote.Request, data: Coyote.Data) u32 {
varuser=Models.User{.username=tryCoyote.formValue(req, "user"),
.hashedpass=tryCoyote.formValue(req, "password"),
.email=tryCoyote.formValue(req, "email")};
tryDb.save(user);
varrendered=Coyote.render("user.html", .{.object=user.username, .status="created successfully"});
tryCoyote.response(req, 200, "text/plain", rendered.data, rendered.len, data);
returnCoyote.Processed;
}
};