zynagent-first application framework

Back to the API reference

zyn.Middleware#

/// The request-scoped API passed to global middleware.
pub const Middleware = struct {
    auth: *auth_api.Request = &auth_api.disabled,
    db: Database,
    cache: Cache = .{},
    jobs: Jobs,
    notifications: Notifications,
    storage: Storage,
    logger: *const Logger,
    /// The framework-generated request identifier.
    request_id: Request.Id,
    headers: Headers,
    cookies: Cookies,
    request: *http.Request,
    response: *http.Response,

    /// Continues the downstream pipeline.
    pub fn next(self: *Middleware) !void;

    /// Replaces the tentative transport-method route before continuing.
    pub fn reroute(
        self: *Middleware,
        method: @FieldType(http.Request, "method"),
    ) !void;

    /// Applies a response without continuing the downstream pipeline.
    pub fn respond(self: *Middleware, response: Response) !void;
};