How can I get argument not separated by / in REST?
Let's say I need to process these urls in one REST method:
http://host:port/REST/arg1/arg2/arg3 http://host:port/REST/arg1/arg2/ http://host:port/REST/arg1/arg2 http://host:port/REST/arg http://host:port/REST/
Currently I need to define URL Map like this (assuming /REST web app):
XData UrlMap
{
<Routes>
<Route Url="/:arg1" Method="GET" Call="GET"/>
<Route Url="/:arg1/:arg2" Method="GET" Call="GET"/>
<Route Url="/:arg1/:arg2/" Method="GET" Call="GET"/>
<Route Url="/:arg1/:arg2/:arg3" Method="GET" Call="GET"/>
</Routes>
} Is there a way to get all these URLs in one route:
XData UrlMap
{
<Routes>
<Route Url="/:arg" Method="GET" Call="GET"/>
</Routes>
}Discussion (5)0
Comments
Ha! Came here to post the same;)
Thank you. That helped.
Class Try.REST Extends %CSP.REST
{
XData UrlMap
{
<Routes>
<Route Url="(.*)" Method="GET" Call="GET"/>
</Routes>
}
ClassMethod GET(href)
{
w "OK"
s ^dbg($i(^dbg)) = $g(href)
q 1
}
}Here's what you could use to get the first three pieces, all optional:
Url="/([^/]*)/?([^/]*)/?([^/]*)"
Note that if there's nothing matched for the nth capturing group, it'll pass an empty string as the nth argument. (So defaults in your method signature won't be helpful.)
In my case I need everything in the url as one argument. But that's also useful for some use cases.