Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Customize File Path

dscape edited this page · 14 revisions

Customize File Path

You can customize file path by override the defaults for:

Element Description Default Value Sample Notes
resourceFormat Overrides the path format so you can use rewrite without the need to call individual functions /:dir/:resource.:ext?action=:action <paths> <resourceFormat>/:resource-:action.:ext</resourceFormat> </paths> e.g. /server-ping.xqy
resourceDirectory Where all the invokable XQuery files are stored. Synonym to controller in a MVC implementation resource <paths> <resourceDirectory>lib</resourceDirectory> </paths> Alias in format replacements is
:resource
staticFormat Overrides the static path format for further customization /:static/:remainder <paths> <staticFormat>/foo/:remainder</staticFormat> </paths> e.g. /foo/css/style.css
staticDirectory Directory to where the system falls back to if invokable module was found static <paths> <staticDirectory>public</staticDirectory> </paths> Alias in format replacements is
:static
redirectFormat Overrides the redirect path format for further customization /:dir/:redirect.:ext?url=:url <paths> <redirectFormat>/:redirect.:ext?url=:url</redirectFormat> </paths> e.g. /dispatcher.xq?url=foo
redirect Controller that is responsible for redirecting requests redirect <paths> <redirect>dispatcher</redirect> </paths> Alias in format replacements is
:redirect
xqyExtension Extension for the invokable files. Either .xqy or .xq xqy <paths> <xqyExtension>xq</xqyExtension> </paths> Alias in format replacements is
:ext

To do so you call the r:selectedRoute\2 function:

 r:selectedRoute( $routesCfg, $defaultCfg )

Here's a quick example of such configuration file:

 <paths>
   <resourceDirectory>/lib/</resourceDirectory>
   <xqyExtension>xq</xqyExtension>
   <staticDirectory>/public/</staticDirectory>
   <redirect>dispatcher</redirect>
 </paths>

Sample Invocation

 xquery version "1.0-ml" ;

 import module namespace r = "routes.xqy" at "/lib/routes.xqy" ;

 declare variable $routesCfg := 
   <routes>
     <root> users#list </root>
     <get path="users/:id">
       <to> users#show </to>
     </get>
   </routes> ;

 declare variable $pathsCfg :=
   <paths>
     <resourceFormat>:resource-:action.:ext</resourceFormat>
     <xqyExtension>xq</xqyExtension>
     <staticDirectory>public</staticDirectory>
     <redirect>dispatcher</redirect>
   </paths> ;

 r:selectedRoute( $routesCfg, $pathsCfg )
Something went wrong with that request. Please try again.