A `Middleware` object wraps a handler function with associated metadata (`path`, `method`, `protocol`). Middleware functions have access to the request (`req`), response (`res`), and error (`err`) objects during the request–response cycle via the [`Router`].

Format

An [`R6::R6Class`] generator for `Middleware` objects.

See also

[Router], [Request], [Response], [Error]

Public fields

path

Path this middleware matches, or `NULL` for all paths.

FUN

Handler function executed when matched.

method

HTTP method to match (e.g., `"GET"`), or `NULL` for any.

protocol

Protocol string: `"http"` or `"websocket"`.

Methods


Method new()

Initialize middleware with handler, path, method, and protocol selection.

Usage

Middleware$new(FUN, path, method, websocket)

Arguments

FUN

Handler function (e.g., `(req, res, err)` for HTTP).

path

Route path to match, or `NULL` for all.

method

HTTP method to match, or `NULL` for any.

websocket

If `TRUE`, set `protocol = "websocket"`; otherwise `"http"`.


Method clone()

The objects of this class are cloneable with this method.

Usage

Middleware$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.