The tulip.pkg.middleware module exports the middleware package. It enables app-level middleware (as opposed to route-specific middleware) in the order specified in the configuration. This means that requests will go through those middleware handlers in that order.


  • array of string|function = the order of the middleware to apply to web requests.

#API Extensions

Registering this package provides the following method and field extensions.

#App(req, res, nxt)

Sets up the __call metamethod on the App's metatable so that it can be used as initial middleware.


  • req: table = the http Request instance
  • res: table = the http Response instance
  • nxt: function|nil = the function that calls the next middleware
#f = App:lookup_middleware(name)

Returns the middleware registered for that name, or nil if none.


  • name: string = the name for the registered middleware


  • f: function = the registered middleware
#App:register_middleware(name, mw)

Registers the middleware mw for name. If there is already a registered middleware for name, throws an error.


  • name: string = the name of the middleware
  • mw: function = middleware function (or callable table)

Resolves the middleware identified by a string in the array mws to their actual function (or callable table).


  • mws: array of string|function = the defined middleware
#App.middleware: array of string|function

The list of middleware to apply to web requests. When the App is called as initial middleware, it triggers that chain of middleware next, in sequence.

Back to index

About this wiki

commit 3ebfbd288b8e5c95fdf8ce2027a0e94cfa1c8976
Author: Martin Angers <martin.n.angers@gmail.com>
Date:   2021-02-25T14:07:12-05:00

Update to reflect Request:validate_body
Clone this wiki
https://git.sr.ht/~mna/tulip-wiki (read-only)
git@git.sr.ht:~mna/tulip-wiki (read/write)