On this page:
dispatch-rules+  roles
dispatch/  mount

9 Dispatch🔗

 (require koyo/dispatch) package: koyo-lib

This module provides syntax for building a role-aware dispatch procedure and dispatcher combinators.

syntax

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

Returns three values: a dispatcher procedure as in dispatch-rules, a procedure that can generate reverse URIs and a procedure that, given a request, can return the required set of roles for the matching dispatch-proc.

Reverse URI generation differs from dispatch-rules in that the first argument must be a symbol representing the name of the route rather than a dispatch-proc. 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 procedure.

procedure

(dispatch/mount root dispatcher)  dispatcher/c

  root : string?
  dispatcher : dispatcher/c
Returns a new dispatcher that reroots incoming requests using request-reroot with the given root before passing the result to dispatcher. Calls next-dispatcher when a request cannot be rerooted.

The rerooted dispatcher is parameterized to cooperate with the reverse-uri procedure, meaning that generating a reverse URL from within a request handler called by the dispatcher results in a URL with the root prepended to it.

Combine dispatch-rules+roles, dispatch/servlet and dispatch/mount to embed modular sub-applications into larger applications where the former have no knowledge of the URL structure of the larger application.

Added in version 0.28 of package koyo-lib.