1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 23:24:09 +00:00

updated readme

This commit is contained in:
Rene Schallner 2023-01-14 16:53:33 +01:00
parent 0b4df3330b
commit b0ca939082
2 changed files with 50 additions and 1 deletions

View file

@ -28,6 +28,9 @@ Here's what works:
server with optional dynamic request handling
- **[hello_json](examples/hello_json/hello_json.zig)**: serves you json
dependent on HTTP path
- **[endpoints](examples/endpoints/)**: a simple JSON REST API example featuring
a `/users` endpoint for adding/deleting/displaying/updating users and a
`/list` endpoint returning the entire user list.
I'll continue wrapping more of facil.io's functionality and adding stuff to zap
to a point where I can use it as the JSON REST API backend for my current
@ -320,3 +323,49 @@ pub fn main() !void {
});
}
```
### [endpoints](examples/endpoints/)
Only showing `main.zig` here:
```zig
const std = @import("std");
const zap = @import("zap");
const Endpoints = @import("endpoints.zig");
pub fn main() !void {
const allocator = std.heap.page_allocator;
// setup listener
var listener = zap.SimpleEndpointListener.init(
allocator,
.{
.port = 3000,
.on_request = null,
.log = true,
.public_folder = "./examples/endpoints/html",
},
);
Endpoints.init(allocator, "/user", "/list");
// add endpoints
try listener.addEndpoint(Endpoints.getUserEndpoint());
try listener.addEndpoint(Endpoints.getUserListEndpoint());
// fake some users
var uid: usize = undefined;
uid = try Endpoints.getUsers().addByName("renerocksai", null);
uid = try Endpoints.getUsers().addByName("renerocksai", "your mom");
// listen
try listener.listen();
std.debug.print("Listening on 0.0.0.0:3000\n", .{});
// and run
zap.start(.{
.threads = 2,
.workers = 2,
});
}
```

@ -1 +1 @@
Subproject commit 063c9bb86e14bae7441d2e37ab7207d9839a98ce
Subproject commit 57ec8fc0f6df4acf45748758a40dffdffc24cba0