Written by

Principal Integration Architect | Cloud Computing | Data Science | AI & ML | CSM
Question Neerav Verma · Dec 19, 2020

REST: Not Supported : "in": "PATH",

I have been using the 

"in": "PATH"

parameter type for at least a year and was working fine for my GET requests.

Now, since this new version, it has stopped compiling. Does someone know why and what's the workaround to make a request like this work

/getmethod/getparam

Regards

Product version: IRIS 2020.1
$ZV: IRIS for Windows (x86-64) 2020.1 (Build 215U) Mon Mar 30 2020 20:14:33 EDT

Comments

Neerav Verma  Dec 19, 2020 to Dmitry Maslennikov

This is a sample spec. note this line

"in":"query",
Now I have to call this rest endpoint as 

http://localhost:52774/csp/restapp/Demo?country=uk
however earlier i had
"in":"path"   
and was calling rest endpoint as 

http://localhost:52774/csp/restapp/Demo/uk.

Now in=path does not even compile. Thus just curious why .
----------------------------------------------------------------


XData OpenAPI [ MimeType = application/json ]
{
{
"swagger":"2.0",
"info":{
"title":"O",
"version":"1"
},
"schemes":[
"http",
"https"
],
"consumes":[
"application/json]"
],
"produces":[
"application/json]"
],
"paths":{
"/Demo":{
"get":{
"summary":"Get Demo ",
"description":"Demo ",
"operationId":"GETDemo",
"x-ISC_CORS":true,
"consumes":[
"application/json]",
"text/html]"
],
"produces":[
"application/json]",
"text/html]"
],
"parameters":[
{
"name":"country",
"type":"string",
"in":"query",
"description":"Country Name",
"allowEmptyValue": true
}],
"responses":{
"200":{
"description":"Returns Country",
"schema": {
"type":"string"
}
}
}
}
}
}
}
}
 

0
Marcio Jose Pedroso Dias  Jan 20, 2021 to Neerav Verma

Did you import the Swagger spec or write the code by yourself?

Indeed, "Path" or "query" aproach does make difference inside the Intersystems structure.

Example:

Class REST.Demo Extends %CSP.REST
{XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap]
{
<Routes>
<Route Url="/Demo/:in" Method="GET" Call="GetPath" Cors="true"/>
<Route Url="/Demo" Method="GET" Call="GetQuery" Cors="true"/>
</Routes>
}ClassMethod GetPath(in As %String) As %Status
{
Set outJSON = ##class(%ZEN.proxyObject).%New()
Set outJSON.in = in
Write outJSON.%ToJSON()
Quit $$$OK
}ClassMethod GetQuery(
pInput As %Library.AbstractStream,
Output pOutput As %Stream.Object) As %Status
{
Set outJSON = ##class(%ZEN.proxyObject).%New()
Set outJSON.Country = $Get( %request.Data( "Country", "1") )
Write outJSON.%ToJSON()
Quit $$$OK
}}
 

0
Jon Willeke  Jan 21, 2021 to Marcio Jose Pedroso Dias

For a "path" parameter, there has to be a corresponding placeholder in the path string. I got this to work with "path" instead of "query" by changing "/Demo" to "/Demo/{country}", which generated a "/Demo/:country" route in the URL map.

0
Neerav Verma  Jan 21, 2021 to Jon Willeke

Can you please paste the openapi spec for that ?

Another factor which I forgot to mention was that the Path was working past 2 years with the openapi spec I had, it only stopped working on the latest 2020 version.

0
Jon Willeke  Jan 21, 2021 to Neerav Verma

I took the spec. from your reply to Dmitriy's question, changed "query" to "path", smooshed it into one line, then pasted it into a terminal:

USER>s swagger={...}

USER>s status=##class(%REST.API).CreateApplication("neerav",swagger)

USER>zw status
... /* ERROR #8722: Path parameter country is not used in url /Demo of route with GETDemo in class: neerav.spec

I then changed "/Demo" to "/Demo/{country}":

USER>s swagger={ "swagger":"2.0","info":{ "title":"O","version":"1" },"schemes":["http","https"],"consumes":["application/json]"],"produces":["application/json]"],"paths":{ "/Demo/{country}":{ "get":{ "summary":"Get Demo ","description":"Demo ","operationId":"GETDemo","x-ISC_CORS":true,"consumes":["application/json]","text/html]"],"produces":["application/json]","text/html]"],"parameters":[{ "name":"country","type":"string","in":"path","description":"Country Name","allowEmptyValue": true } ],"responses":{ "200":{ "description":"Returns Country","schema": { "type":"string" } } } } } } }

USER>s status=##class(%REST.API).CreateApplication("neerav",swagger)

USER>zw status
status=1

I'm curious to know in what version this previously worked. I get the same error in 2019.1.2.

0
Neerav Verma  Jan 21, 2021 to Jon Willeke

It used to work on IRIS 2019.. Now I don't remember what version of 2019. I think it was 2019.1.1 but can't bet on it.

0