MarkLogic 10 Product Documentation
rest:rewrite

rest:rewrite(
   $options as element(rest:options),
   $match-criteria as xs:string+
) as xs:string?

Summary

This function is used in the URL rewriter to map the incoming request to an endpoint. By default, if you supply only options, all aspects of the request environment are used for rewriting. 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 that defines the request.
match-criteria Criteria to be used in matching request rules for rewriting. By default, all are used. Supply one or more of: "uri", "accept", "conditions","method", "params".

Example

  xquery version "1.0-ml"; 
 
  import module namespace rest="http://marklogic.com/appservices/rest"
      at "/MarkLogic/appservices/utils/rest.xqy";

  declare default function namespace "http://www.w3.org/2005/xpath-functions";

  declare option xdmp:mapping "false";

  let $options :=
    <rest:options>
      <rest:request uri="^/shake/endpoint/(.+)/(\d+)$" 
		    endpoint="/shake/endpoint.xqy">
        <rest:uri-param name="play">$1.xml</rest:uri-param>
        <rest:uri-param name="act" as="decimal">$2</rest:uri-param>
      </rest:request>
      <rest:request uri="^/shake/endpoint/(.+)/?$" 
	      endpoint="/shake/endpoint.xqy">
        <rest:uri-param name="play">$1.xml</rest:uri-param>
      </rest:request>
    </rest:options>
 
  let $rewrite := rest:rewrite($options)
 
  return
    $rewrite

    (: Rewrites a URL ending with either /shake/endpoint/play or 
       /shake/endpoint/play/{number} for execution by the 
       endpoint.xqy module. :)
    

Example

  xquery version "1.0-ml"; 
 
  import module namespace rest="http://marklogic.com/appservices/rest"
      at "/MarkLogic/appservices/utils/rest.xqy";

  declare default function namespace "http://www.w3.org/2005/xpath-functions";

  declare option xdmp:mapping "false";

  let $options :=
    <rest:options>
       <rest:request uri="^/shake/endpoint/(.+)/(\d+)$" 
		    endpoint="/shake/endpoint.xqy">
        <rest:uri-param name="play">$1.xml</rest:uri-param>
        <rest:uri-param name="act" as="decimal">$2</rest:uri-param>
        <rest:http method="GET POST"/>
      </rest:request>
      <rest:request uri="^/shake/endpoint/(.+)/?$" 
	      endpoint="/shake/endpoint.xqy">
        <rest:uri-param name="play">$1.xml</rest:uri-param>
        <rest:http method="GET POST"/>
      </rest:request>
    </rest:options>
 
  let $rewrite := rest:rewrite($options,("uri","method"))
 
  return
    $rewrite

    (: Rewrites a URL ending with either /shake/endpoint/play or 
       /shake/endpoint/play/{number} for execution by the endpoint.xqy 
       module, taking into account uri and request method but ignoring 
       other criteria such as parameters and user agent. :)
    
Powered by MarkLogic Server | Terms of Use | Privacy Policy