Thanks Colleen, for us at this stage it was really just as simple as modifying 
the URL pattern our users would have to work with. It's not really something 
that pressing for us to change it but it would have been nice to be able to 
customize.

I appreciate all of you other suggestions and will be sure to keep them in mind 
as we proceed.

-Zach

From: [email protected] 
[mailto:[email protected]] On Behalf Of Colleen Whitney
Sent: Thursday, August 01, 2013 10:21 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Modifying rewriter.xqy

Hi Zach,

I think it might be better to start with a little more information about *why* 
you're trying to modify the rewriter.  That's important, because if there's 
another way to accomplish what you're trying to do without changing this code, 
you'll be much happier when you go to upgrade in the future (because that code 
will be replaced during upgrade).

I'm going to make a wild guess that you're trying to do two things:

 * Make your "appl" options the default options that are called on every call 
to the search endoint.

 * Make requests starting with /item/ map to a particular call to the documents 
endpoint.

If that's correct, then I have two suggestions that might make it possible for 
you to get what you want without touching the rewriter.

* You can set your "appl" options as your default options by persisting them 
using the special name "default"  (the same way you did when configuring your 
"appl" options).

* You can create an extension to the API that accomplishes the second task if 
you don't mind that your URL pattern isn't starting with /item.

--Colleen

________________________________
From: 
[email protected]<mailto:[email protected]>
 [[email protected]] on behalf of Dunlap, Zachariah 
[[email protected]]
Sent: Thursday, August 01, 2013 7:04 AM
To: [email protected]<mailto:[email protected]>
Subject: [MarkLogic Dev General] Modifying rewriter.xqy
I'd like to make some modifications to rewriter.xqy found at: 
/MarkLogic/rest-api/rewriter.xqy.

I've copied rewrite.xqy and changed it as follows:

xquery version "1.0-ml";

(: Copyright 2011-2013 MarkLogic Corporation.  All Rights Reserved. :)
import module namespace amped-common = 
"http://marklogic.com/appservices/util-amped";
    at "/MarkLogic/appservices/utils/common-amped.xqy";

amped-common:appservices-check-license-valid();

import module namespace rest = "http://marklogic.com/appservices/rest";
    at "/MarkLogic/appservices/utils/rest.xqy";

import module namespace conf = "http://marklogic.com/rest-api/endpoints/config";
    at "/MarkLogic/rest-api/endpoints/config.xqy";

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

let $uri  := xdmp:get-request-url()
let $customuri := if (fn:starts-with($uri, "/search?q=")) then fn:replace($uri, 
"^/search\?q=", "/v1/search?options=appl&amp;q=")
    else if (fn:starts-with($uri, "/item/")) then fn:replace($uri, "/item/", 
"/v1/documents?format=xml&amp;uri=/content/")
    else $uri

return (
        conf:rewrite(xdmp:get-request-method(), $customuri, 
xdmp:get-request-path()),
        $customuri
        )[1]

Unfortunately, it seems that anything after the ? in my fn:replace statement is 
getting dropped. I gather this is because there is something in config.xqy or 
elsewhere that is saying the ? should be the end of the line, but I can't 
locate it. I've tried URL encoding the ? but that doesn't work either.

If anyone has any suggestions on how I can get past this hurdle or can suggest 
a better way for me to achieve what I'm trying to do, I welcome your input.

Thanks,

Zach

The information contained in this communication is intended for the use
of the designated recipients named above. If the reader of this
communication is not the intended recipient, you are hereby notified
that you have received this communication in error, and that any review,
dissemination, distribution or copying of this communication is strictly
prohibited. If you have received this communication in error, please
notify The Associated Press immediately by telephone at +1-212-621-1898
and delete this email. Thank you.
[IP_US_DISC]


msk dccc60c6d2c3a6438f0cf467d9a4938
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to