Question
· Jul 4

forward REST calls and retain path parameters

Hi, I have a controller which handles accounts, and forwards to the relevant controller based on the path, example below:

XData UrlMap
{
<Routes>

<Map Prefix="/:accountId/anothercontroller" Forward="AnotherController"/>

</Routes>
}

Problem is that inside AnotherController, the accountId path parameter is lost, I assume that's because the map forward simply checks if there's a match then forwards.

AnotherController:

XData UrlMap
{
<Routes>

<Route Url="/:somethingId" Method="POST" Call="CreateSomething"/>

</Routes>
}
ClassMethod CreateSomething(somethingId)
{
}

The reason for this is because I don't want to specify the same route including the accountId for many routes, instead is it possible to forward the accountId to get something like this:

XData UrlMap
{
<Routes>

<Route Url="/:somethingId" Method="POST" Call="CreateSomething"/>

</Routes
}
/// accountId passed through and accessible
ClassMethod CreateSomething(accountId, somethingId)
{
}

 

We'll be upgrading to IRIS soon, so if it is possible there I'd love to know where I can read more about how to do so.

Thank you.

Product version: Caché 2017.1
$ZV: Cache for UNIX (Red Hat Enterprise Linux for x86-64) 2017.1 (Build 792U) Mon Mar 20 2017 19:19:52 EDT
Discussion (2)0
Log in or sign up to continue

Hello @Martin Nielsen

I did some analysis about this. As of my understanding, I found this is because of the method DispatchRequest in the %CSP.REST. The below piece of code is actually skip your accountId due to forward your request to another "DispatchRequest" in the other dispatch class(for your case "AnotherController" class). But these are rewritten in IRIS already. You can try override this method for testing.

Set tMatchUrl=$Piece(tMatchUrl,tMatchcher.Group(1),"2",*),tForward=$LisGet(tMapEntry,3)
Actual Url: /1001/anothercontroller/001
Url after above line executed: /001