rest:matching-request( $options as element(rest:options), $match-criteria as xs:string+ ) as element(rest:request)?
This function returns the request
element in
the options
node that matches the specified URI. If
you only specify options parameter, all criteria in the request
environment are considered. If you supply specific criteria, the
filter is less strict, allowing the same options block to be used
for simple url-based rewriting as well as request processing.
Parameters | |
---|---|
options | The options node. |
match-criteria | Criteria to be used in matching request rules. By default, all are used. Supply one or more of: "uri", "accept", "conditions","method", "params". |
xquery version "1.0-ml"; import module namespace rest="http://marklogic.com/appservices/rest" at "/MarkLogic/appservices/utils/rest.xqy"; declare option xdmp:mapping "false"; let $options := <options xmlns="http://marklogic.com/appservices/rest"> <request uri="^/shakespeare/(.+)/(.+)" endpoint="/redirect.xqy"> <uri-param name="__ml_redirect__">/$1/$2</uri-param> </request> <request uri="^/shakespeare/(.+)" endpoint="/redirect.xqy"> <uri-param name="__ml_redirect__">/$1</uri-param> </request> <request uri="^/(.+)/act(\d+)" endpoint="/endpoint.xqy"> <uri-param name="play">$1.xml</uri-param> <uri-param name="act" as="integer">$2</uri-param> <param name="scene" as="integer" values="1|2|3" default="1"/> </request> <request uri="^/(.+)$" endpoint="/endpoint.xqy"> <uri-param name="play">$1.xml</uri-param> </request> <request uri="^(.+)$" endpoint="/options.xqy" user-params="allow"> <uri-param name="__ml_options__">$1</uri-param> <http method="OPTIONS"/> </request> </options> let $uri := "/shakespeare/hamlet" return rest:matching-request($options, "uri") (: Returns the request node that matches the URI, "/shakespeare/hamlet". :)
xquery version "1.0-ml"; import module namespace rest="http://marklogic.com/appservices/rest" at "/MarkLogic/appservices/utils/rest.xqy"; declare option xdmp:mapping "false"; let $options := <options xmlns="http://marklogic.com/appservices/rest"> <request uri="^/shakespeare/(.+)/(.+)" endpoint="/redirect.xqy"> <uri-param name="__ml_redirect__">/$1/$2</uri-param> </request> <request uri="^/shakespeare/(.+)" endpoint="/redirect.xqy"> <uri-param name="__ml_redirect__">/$1</uri-param> </request> <request uri="^/(.+)/act(\d+)" endpoint="/endpoint.xqy"> <uri-param name="play">$1.xml</uri-param> <uri-param name="act" as="integer">$2</uri-param> <param name="scene" as="integer" values="1|2|3" default="1"/> </request> <request uri="^/(.+)$" endpoint="/endpoint.xqy"> <uri-param name="play">$1.xml</uri-param> </request> <request uri="^/(.+)$" endpoint="/delete.xqy"> <http method="DELETE"/> <param name="reason" required="true"/> </request> <request uri="^(.+)$" endpoint="/options.xqy" user-params="allow"> <uri-param name="__ml_options__">$1</uri-param> <http method="OPTIONS"/> </request> </options> let $uri := "/shakespeare/hamlet" let $accept := xdmp:get-request-header("Accept") let $params := map:map() return rest:matching-request($options, ("uri","method")) (: Returns the request node contining "/delete.xqy" with a DELETE request for URI, "/myplay", ignoring the missing parameter :)