HTTP dispatcher examples
Furnace framework » HTTP server » HTTP dispatchers and virtual hosting

Next:dispatcher


Simple pathname dispatcher
<dispatcher> <new-action> "new" add-responder <edit-action> "edit" add-responder <delete-action> "delete" add-responder <list-action> "" add-responder main-responder set-global

In the above example, visiting any URL other than /new, /edit, /delete, or / will result in a 404 error.

Another pathname dispatcher
On the other hand, suppose we wanted to route all unrecognized paths to a “view” action:
<dispatcher> <new-action> "new" add-responder <edit-action> "edit" add-responder <delete-action> "delete" add-responder <view-action> >>default main-responder set-global

The default slot holds a responder to which all unrecognized paths are sent to.

Dispatcher subclassing example
TUPLE: golf-courses < dispatcher ; : <golf-courses> ( -- golf-courses ) golf-courses new-dispatcher ; <golf-courses> <new-action> "new" add-responder <edit-action> "edit" add-responder <delete-action> "delete" add-responder <list-action> "" add-responder main-responder set-global

The action templates can now emit links to responder-relative URLs prefixed by $golf-courses/.

Virtual hosting example
<vhost-dispatcher> <casino> "concatenative-casino.com" add-responder <dating> "raptor-dating.com" add-responder main-responder set-global

Note that the virtual host dispatcher strips off a www. prefix, so www.concatenative-casino.com would be routed to the <casino> responder instead of receiving a 404.