Hi Amit,

The built-in routing is intended to use main as the default function, so this 
path: "/topics" would normally go to the topics' controller's main function, 
while "/topics/topics" would go to the topics function in the topics 
controller. I see that you want the simpler URL path to go to the topics 
function instead.

I played around with your example for a bit and I got it to work by changing 
the endpoint:

    <request uri="^/topics/?(.*)$" endpoint="/roxy/query-router.xqy">
      <uri-param name="controller" default="topics"></uri-param>
      <uri-param name="func">topics</uri-param>
      <uri-param name="format" default="json"></uri-param>
      <http method="GET"/>
      <http method="HEAD"/>
    </request>

The endpoint can't point to the controller itself, because the target needs to 
be a main module. I see that you had it pointing to "/app/restful-router.xqy". 
I don't know what that one does, but it doesn't need to do much. You might want 
to just copy the src/roxy/query-router.xqy code into there and see how that 
works (better not to directly point to code under src/roxy, as that can change).

Dave.

--
Dave Cassel<http://davidcassel.net>, @dmcassel<https://twitter.com/dmcassel>
Technical Community Manager
MarkLogic Corporation<http://www.marklogic.com/>
http://developer.marklogic.com/


From: 
<[email protected]<mailto:[email protected]>>
 on behalf of amit gope <[email protected]<mailto:[email protected]>>
Reply-To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Date: Friday, November 25, 2016 at 11:04 PM
To: "[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>
Subject: [MarkLogic Dev General] Roxy request not getting properly redirected.

Hi All,

I am using a roxy configuration and I created an endpoint routing like this to 
the list of existing routing definitions:

    <request uri="^/topics/?(.*)$" endpoint="/app/restful-router.xqy">
      <uri-param name="controller" default="topics"></uri-param>
      <uri-param name="func">topics</uri-param>
      <uri-param name="format" default="json"></uri-param>
      <http method="GET"/>
      <http method="HEAD"/>
    </request>

and I created a controller named topics.xqy, a model named topics-model.xqy and 
views topics

This is how my topics contoller looks like

xquery version "1.0-ml";
module namespace c = "http://marklogic.com/roxy/controller/topics";;
import module namespace ch    = "http://marklogic.com/roxy/controller-helper"; 
at "/roxy/lib/controller-helper.xqy";
import module namespace req   = "http://marklogic.com/roxy/request"; at 
"/roxy/lib/request.xqy";
import module namespace error = "http://marklogic.com/roxy/error-lib"; at 
"../views/helpers/error-lib.xqy";
import module namespace topics  = "http://marklogic.com/roxy/models/topics"; at 
"/app/models/topics-model.xqy";

declare option xdmp:mapping "false";
declare variable $RES-TYPE as xs:string := "Topics";
declare variable $ALL-FORMATS as xs:string+ := ("html", "xml", "json", "text");
(: Default function that is returns an error message :)

declare function c:main() as item()*
{
  error:error-handling( 500, fn:concat("Not supported, not sure why"))

};

declare function c:topics() as item()*
{
let $result := topics:topics("RBO-TOPIC-ROOT","parents","", "ALL")
return (
ch:use-view("topics/topics",$ALL-FORMATS),
    ch:add-value("result", $result),
    ch:add-value(
      "res-header",
      element header {
        element Date {fn:current-dateTime()},
        element Location {fn:concat("/",fn:lower-case($RES-TYPE),())},
        element Content-Type {req:get("req-header")/content-type/fn:string()}
      }
    )
  )};

The model has the code of getting me the topics as per my application 
requirement.

When I make a request through postman like this http://localhost:8018/topics it 
always goes to the main function and throws the error, and never goes to the 
desired topics function. Why is that so? What mistake am I doing. Please 
suggest.

Best Regards
Amit

_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to