diff --git a/README.md b/README.md index 8114739..2224266 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ 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 +- **[endpoint](examples/endpoint/)**: a simple JSON REST API example featuring a `/users` endpoint for PUTting/DELETE-ing/GET-ting/POST-ing and listing users, together with a static HTML and JavaScript frontend to play with. @@ -394,18 +394,19 @@ pub fn main() !void { } ``` -### [endpoints](examples/endpoints/) +### [endpoint](examples/endpoint/) -The following only shows the GET functionality implemented on both the `/user/` -and the `/list` endpoints. See [endpoints](examples/endpoints/) for a complete +The following only shows the GET functionality implemented on the `/users/` +See [endpoint](examples/endpoint/) for a complete example, including an HTML + JavaScript frontend. -[`main.zig`](examples/endpoints/main.zig): +[`main.zig`](examples/endpoint/main.zig): ```zig + const std = @import("std"); const zap = @import("zap"); -const Endpoints = @import("endpoints.zig"); +const Endpoint = @import("endpoint.zig"); pub fn main() !void { const allocator = std.heap.page_allocator; @@ -416,19 +417,19 @@ pub fn main() !void { .port = 3000, .on_request = null, .log = true, - .public_folder = "./examples/endpoints/html", + .public_folder = "./examples/endpoint/html", }, ); - Endpoints.init(allocator, "/users"); + Endpoint.init(allocator, "/users"); // add endpoint - try listener.addEndpoint(Endpoints.getUserEndpoint()); + try listener.addEndpoint(Endpoint.getUserEndpoint()); // fake some users var uid: usize = undefined; - uid = try Endpoints.getUsers().addByName("renerocksai", null); - uid = try Endpoints.getUsers().addByName("renerocksai", "your mom"); + uid = try Endpoint.getUsers().addByName("renerocksai", null); + uid = try Endpoint.getUsers().addByName("renerocksai", "your mom"); // listen try listener.listen(); @@ -444,7 +445,7 @@ pub fn main() !void { ``` -[`endpoints.zig`](examples/endpoints/endpoints.zig): +[`endpoint.zig`](examples/endpoint/endpoint.zig): ```zig const std = @import("std"); diff --git a/build.zig b/build.zig index 8cbcac4..a02f249 100644 --- a/build.zig +++ b/build.zig @@ -23,7 +23,7 @@ pub fn build(b: *std.build.Builder) !void { .{ .name = "routes", .src = "examples/routes/routes.zig" }, .{ .name = "serve", .src = "examples/serve/serve.zig" }, .{ .name = "hello_json", .src = "examples/hello_json/hello_json.zig" }, - .{ .name = "endpoints", .src = "examples/endpoints/main.zig" }, + .{ .name = "endpoint", .src = "examples/endpoint/main.zig" }, .{ .name = "wrk", .src = "wrk/zig/main.zig" }, }) |excfg| { const ex_name = excfg.name; diff --git a/examples/endpoints/endpoints.zig b/examples/endpoint/endpoint.zig similarity index 100% rename from examples/endpoints/endpoints.zig rename to examples/endpoint/endpoint.zig diff --git a/examples/endpoints/html/index.html b/examples/endpoint/html/index.html similarity index 100% rename from examples/endpoints/html/index.html rename to examples/endpoint/html/index.html diff --git a/examples/endpoints/main.zig b/examples/endpoint/main.zig similarity index 63% rename from examples/endpoints/main.zig rename to examples/endpoint/main.zig index 0c08c09..407afed 100644 --- a/examples/endpoints/main.zig +++ b/examples/endpoint/main.zig @@ -1,6 +1,6 @@ const std = @import("std"); const zap = @import("zap"); -const Endpoints = @import("endpoints.zig"); +const Endpoint = @import("endpoint.zig"); pub fn main() !void { const allocator = std.heap.page_allocator; @@ -11,19 +11,19 @@ pub fn main() !void { .port = 3000, .on_request = null, .log = true, - .public_folder = "./examples/endpoints/html", + .public_folder = "./examples/endpoint/html", }, ); - Endpoints.init(allocator, "/users"); + Endpoint.init(allocator, "/users"); // add endpoint - try listener.addEndpoint(Endpoints.getUserEndpoint()); + try listener.addEndpoint(Endpoint.getUserEndpoint()); // fake some users var uid: usize = undefined; - uid = try Endpoints.getUsers().addByName("renerocksai", null); - uid = try Endpoints.getUsers().addByName("renerocksai", "your mom"); + uid = try Endpoint.getUsers().addByName("renerocksai", null); + uid = try Endpoint.getUsers().addByName("renerocksai", "your mom"); // listen try listener.listen(); diff --git a/examples/endpoints/users.zig b/examples/endpoint/users.zig similarity index 100% rename from examples/endpoints/users.zig rename to examples/endpoint/users.zig diff --git a/introducing.md b/introducing.md index 9adfc4f..9a4d6d2 100644 --- a/introducing.md +++ b/introducing.md @@ -24,7 +24,7 @@ Here's what works: - **[routes](https://github.com/renerocksai/zap/blob/master/examples/routes/routes.zig)**: a super easy example dispatching on the HTTP path - **[serve](https://github.com/renerocksai/zap/blob/master/examples/serve/serve.zig)**: the traditional static web server with optional dynamic request handling - **[hello_json](https://github.com/renerocksai/zap/blob/master/examples/hello_json/hello_json.zig)**: serves you json dependent on HTTP path -- **[endpoints](https://github.com/renerocksai/zap/blob/master/examples/endpoints/)**: a simple JSON REST API example featuring a `/users` endpoint for PUTting/DELETE-ing/GET-ting/POST-ing users and a `/list` endpoint returning the entire user list on GET, together with a static HTML and JavaScript frontend to play around with. +- **[endpoint](https://github.com/renerocksai/zap/blob/master/examples/endpoint/)**: a simple JSON REST API example featuring a `/users` endpoint for PUTting/DELETE-ing/GET-ting/POST-ing and listing users, together with a static HTML and JavaScript frontend to play around with. If you want to take it for a quick spin: