On this page:
dispatch-rules+  roles

9 Dispatch

 (require koyo/dispatch) package: koyo-lib

This module provides syntax for building a role-aware dispatch function.


(dispatch-rules+roles dispatch-clause ... maybe-else-clause)

dispatch-clause = [dispatch-pattern maybe-method maybe-roles maybe-name dispatch-fun]
dispatch-pattern = ()
  | (string . dispatch-pattern)
  | (bidi-match-expander ... . dispatch-pattern)
  | (bidi-match-expander . dispatch-pattern)
maybe-method = 
  | #:method method
maybe-roles = 
  | #:roles (role ...)
maybe-name = 
  | #:name name
maybe-else-clause = 
  | [else else-fun]
method = pat
role = id
name = symbol?
  else-fun : (-> request? response?)
  dispatch-fun : (-> request? any/c ... response?)
Like dispatch-rules but each dispatch-clause takes an optional list of roles and an optional name.

Returns three values: the first being a dispatcher function like in dispatch-rules, the second a function that can generate reverse URIs and the third a function that, given a request, can return the required set of roles for the matching dispatch-fun.

Reverse URI generation is different from dispatch-rules in that the first argument is a symbol representing the name of the route rather than the specific dispatch-fun that was used. This helps avoid deep dependency chains between routes. The name for a route is either the value passed to maybe-name or the name of its dispatch function.