-
Notifications
You must be signed in to change notification settings - Fork 1
Advanced HTTP Routing
This document describes the advanced usage of routing system.
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"))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
)The arguments passed to a action are controllable. Use the following keywords
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).
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.
- Home
- Getting Started
- Basic Usage
- Advanced Topics
- APIs
- eloquent.mvc.config
- eloquent.mvc.controller