Written by

Senior Cloud Architect at InterSystems
Question Eduard Lebedyuk · Mar 28, 2017

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>
}

Comments

Fabian Haupt  Mar 28, 2017 to Timothy Leavitt

Ha! Came here to post the same;)

0
Eduard Lebedyuk  Mar 28, 2017 to Timothy Leavitt

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
}

}
0
Timothy Leavitt  Mar 28, 2017 to Timothy Leavitt

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.)

0
Eduard Lebedyuk  Mar 28, 2017 to Timothy Leavitt

In my case I need everything in the url as one argument. But that's also useful for some use cases.

0