1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 15:14:08 +00:00

fix doc comment for new Endpoint

This commit is contained in:
renerocksai 2025-03-16 13:39:52 +01:00
parent d0cb7520ac
commit 7aae77b034
No known key found for this signature in database

View file

@ -10,40 +10,38 @@ pub const fio = @import("fio.zig");
pub const Tls = @import("tls.zig"); pub const Tls = @import("tls.zig");
/// Endpoint and supporting types. /// Endpoint and supporting types.
/// Create one and pass in your callbacks. Then, /// Create one and define all callbacks. Then, pass it to a HttpListener's
/// pass it to a HttpListener's `register()` function to register with the /// `register()` function to register with the listener.
/// listener.
/// ///
/// **NOTE**: A common endpoint pattern for zap is to create your own struct /// **NOTE**: Endpoints must define the following:
/// that embeds an Endpoint, provides specific callbacks, and uses ///
/// `@fieldParentPtr` to get a reference to itself. /// ```zig
/// path: []const u8,
/// pub fn get(_: *Self, _: zap.Request) void {}
/// pub fn post(_: *Self, _: zap.Request) void {}
/// pub fn put(_: *Self, _: zap.Request) void {}
/// pub fn delete(_: *Self, _: zap.Request) void {}
/// pub fn patch(_: *Self, _: zap.Request) void {}
/// pub fn options(_: *Self, _: zap.Request) void {}
/// // optional, if auth stuff is used:
/// pub fn unauthorized(_: *Self, _: zap.Request) void {}
/// ```
/// ///
/// Example: /// Example:
/// A simple endpoint listening on the /stop route that shuts down zap. /// A simple endpoint listening on the /stop route that shuts down zap. The
/// The main thread usually continues at the instructions after the call to zap.start(). /// main thread usually continues at the instructions after the call to
/// zap.start().
/// ///
/// ```zig /// ```zig
/// const StopEndpoint = struct { /// const StopEndpoint = struct {
/// ep: zap.Endpoint = undefined,
/// ///
/// pub fn init( /// pub fn init( path: []const u8,) StopEndpoint {
/// path: []const u8,
/// ) StopEndpoint {
/// return .{ /// return .{
/// .ep = zap.Endpoint.init(.{
/// .path = path, /// .path = path,
/// .get = get,
/// }),
/// }; /// };
/// } /// }
/// ///
/// // access the internal Endpoint /// pub fn get(self: *StopEndpoint, r: zap.Request) void {
/// pub fn endpoint(self: *StopEndpoint) *zap.Endpoint {
/// return &self.ep;
/// }
///
/// fn get(e: *zap.Endpoint, r: zap.Request) void {
/// const self: *StopEndpoint = @fieldParentPtr("ep", e);
/// _ = self; /// _ = self;
/// _ = r; /// _ = r;
/// zap.stop(); /// zap.stop();