Skip to content

HTTP Routing

LiuTao edited this page Nov 11, 2016 · 9 revisions

Format

Routing rules is the result parsed from file config/router.lisp. Here is an example:

((:get "/foobar" foobar::foobar))

Each element in the top-level list form is a routing rule. The first, second and third part of a rule are HTTP method, path pattern and action name respectively.

HTTP method

The HTTP method is a keyword. :get matches GET, :post matches POST, etc.

Path pattern

The second part of routing rule, path pattern, is either a string or a list whose first element if one of the following keywords:

:normal
:regexp
:strict

:normal

If the first element is :normal, the path of request matches the pattern if they're equivalent according to function CL:STRING=, except the slash character at the end if exists. For example, request's path /foobar and /foobar/ both match the pattern (:normal "/foobar").

:regexp

If the first element is :regexp, the path of request matches the pattern if the path contains a sub-string matches against the regular expression pattern. For example, request's path /post/abc and /post/def both matches the pattern (:regexp "/post/\\w+").

:strict

:strict is similar to :normal, except that in this mode the slash character at the end is unignorable.

Action

The name of the function will be invoked when the rule matched

Clone this wiki locally