[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
.png)
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!
Comments
Neat! Didn't know it is possible to use regular expressions in the map! Thanks for sharing, @Kurro Lopez !
According to RFC 9110 (HTTP Semantics), only the scheme and the host are case-insensitive