Article
· 5 hr ago 1m read

[Quick tip] - How to use case insensitive url in REST API Business Service

Hi all,

This is a quick tip about how to use case insensitive URL in REST API.

If you have a class that extends from %CSP.REST and Ens.BusinessService, to create a REST API service, and you have defined your WebApplication in lowercase

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

Only accepts the url in lowercase, i.e. http://myserver/myproduction/user

If you have any uppercase character, the url doesn't work. http://MyServer/MyProduction/user

It is easy to fix, only add the regular expression (?i) to allow case insensitive path.

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

Now, it can accept both URL:

http://myserver/myproduction/user

http://MyServer/MyProduction/user

Happy code!

Discussion (0)1
Log in or sign up to continue