REST API method name Case insensitive

Hi all,

I've a RESP API service in a Business Service to server different methods

I've created the route with the name of the method, each one has been created in lowercase 

XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
{
<Routes>
    <Route Url="/user" Method="POST" Call="User"/>
    <Route Url="/emailactivation" Method="POST" Call="EmailActivation" />
    <Route Url="/login" Method="POST" Call="Login"/>
</Routes>
}

But only there is a response if the call is used in lowercase

http://localhost:57772/mynamespace/emailactivation

my question is, is it possible to create a case insensitive  method name?

Best regards

  • 0
  • 0
  • 281
  • 0
  • 2

Answers

When you define UrlMap, you should remember, that Caché uses Regular expressions. So, you can just put (?i) before Url, to make regular expression case insensitive

XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
{
<Routes>
    <Route Url="(?i)/user" Method="POST" Call="User"/>
    <Route Url="(?i)/emailactivation" Method="POST" Call="EmailActivation" />
    <Route Url="(?i)/login" Method="POST" Call="Login"/>
</Routes>
}

Adding this to your REST broker may help:

/// Dispatch a REST request according to URL and Method
ClassMethod DispatchRequest(pUrl As %String, pMethod As %String, pForwarded As %Boolean = 0) As %Status
{
    set pUrl = $zcvt(pUrl, "l")
    quit ##super(pUrl, pMethod, pForwarded)
}