uri-dispatch is a simple mechanism to dispatch uris to procedures. This is useful for webprogramming where you might want to map uris of a certain kind to procedures that implement the logic for those uris.

The main interface to dispatch-uri. This procedure invokes the dispatch-mechanism with the supplied uri. The dispatch-algorithm is implemented as follows:

(Note Although not explicitly stated here the algorithm performs a whitelist-check on any procedure before it is invoked. See enable-checks and whitelist!)

The path is empty. It checks if default-dispatch-target is non-false. If it is, then it is invoked. If it is not dispatch-error is invoked.

The path has exactly one element. It assumes that this is this element is the name of a thunk that was defined outside a module. If the such a thunk exists it is invoked. If no such a thunk exists it invokes dispatch-error.

The path contains at least two elements.

It checks if the second element is a procedure defined in a module named by the first element. So if it sees (foo bar) it tries to find the procedure foo inside the module bar. If the procedure exists it is invoked with the rest of the elements as arguments.

If it does not exist, it interpretes the first element as the name of a procedure that was defined outside any module. If such a procedure exists, it is invoked passing the rest of the elements as arguments. If no such procedure exists dispatch-error is invoked with the full path as argument. The path is applied to the procedure so you can use for example dsssl-style lambdalists to declare optional arguments or a rest-argument.

[procedure](whitelist! DEFINITION)

Though nice for development it is not advisable to allow anybody out there to invoke abritary procedures of your application. So you might want to enable-checks in production and whitelist only those modules and/or procedures you really want to be callable from the outside. Whitelisting can be done with this procedure. It expects a list that defines the procedure/modules you want to whitelist. If a procedure is requested that does exist but is not whitelisted dispatch-error is invoked. You have basically three possibilities to perform whitelisting all of which can be combined.

It is planned to implement some keywords that allow easier use of this procedure.

[parameter]dispatch-error

If no handler for a uri can be found, the dispatcher will invoke the procedure that dispatch-error is currently parameterized with. NOTE dispatch-error is also invoked if the requested handler exists but is not whitelisted.

[parameter]enable-checks

If set to #t then whitelist-checks are enabled. Defaults to #f.

[parameter]default-dispatch-target

A thunk that is invoke when the uri-path was empty. If set to #f then an empty path leads to the invocation of dispatch-error. Defaults to #f.

[parameter]dispatch-environment

The environment that is used to lookup the procedures. It defaults to current-interaction-environment.