Skip to content

Advanced HTTP Routing

LiuTao edited this page Nov 12, 2016 · 5 revisions

Overview

This document describes the advanced usage of routing system.

URI-template

The mode of a URI-template, such as :normal, is customizable. Developers're able to create new mode, only need to specialize the generic function ELOQUENT.MVC.ROUTER:PATH-INFO= for the new mode. For example, the following code defines a new mode, called :foobar, which would be matched only when the request's path is /foobar:

(defmethod eloquent.mvc.router:path-info= ((mode (eql :foobar)) (path-info string) (uri-template string))
  (declare (ignorable uri-template))
  (string= path-info "/foobar"))

Action

The components as variables in a path pattern, such as :id in pattern /post/:id, can be extracted after rule matching, and passed to the action when be invoking. Specify the action like the following list can do this:

((:get (:template "/post/:id") (foobar::foobar id)))

And the action foobar::foobar must be defined as followed:

(defun foobar (request &key id)
  ;;; Business logics here
  )

Invoke action

The arguments passed to a action are controllable. Use the following keywords

:QUERY-STRING-BIND

this option controls the keyword arguments passed to a action. The value of this option has the following structure:

"(" ["(" variable-name query-string-field ")"]* ")"

The variable-name would bind to a value extract from request's query string by the key query-string-field, and all variables will be passed to action as keyword arguments. For example, if this option's value if ((url "url")), the action is called like (action request :url url-from-query-string).

:REQUESTP

If this argument is set to nil, the instance of current HTTP request would not be passed to the action as the first argument. Default is t.

Clone this wiki locally