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>
}
ObjectScriptObjectScript
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)
{
}
ObjectScriptObjectScript
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)
{
}
ObjectScriptObjectScript
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.
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)
I was hoping I didn't have to do that, that's fine it wasn't as complicated eitherway. Thank you