~mna/tulip

The tulip.pkg.wroutes module exports the wroutes package. It registers a route multiplexer where each message is routed to a specific handler based on the queue name, with optional route-specific middleware applied.

#Dependencies

  • tulip.pkg.wmiddleware

#Configuration

  • Array of tables: the configuration is an array of route tables where each table can have the following fields:
    • wmiddleware: array of string|function = the wmiddleware to apply to this route
    • handler: string|function = the final wmiddleware to apply to this route
    • pattern: string = the Lua pattern that the queue must match for this route
    • any other field on the route will be stored on the Request instance under the routeargs field.

The wmiddleware handlers receive the message instance as argument as well as a next function to call the next middleware. The pattern does not have to be anchored, and if it contains any captures, those are provided on the message object in the queueargs field, as an array of values.

The configuration table can also have the following non-array field:

  • not_found (function): handler to call if no route matches the message. The default not found handler is a no-op (the message is not marked as done).

#Registered Wmiddleware

The following wmiddleware (worker middleware) are registered and can be referenced by name in the configuration.

#tulip.pkg.wroutes

Routes the message to the matching route, or the not_found handler.

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)