How do I process queryString parameters in a HttpGet Request in a %CSP.REST page?

So by queryString I mean name-value pairs passed  in as part of the URL. Currently my service works when called like this
http://{{SERVER}}:{{PORT}}/bsolabs/api/codemanagement/testcode/BIO/CRP

What would I need to change so I can call it like this?
http://{{SERVER}}:{{PORT}}/bsolabs/api/codemanagement/testcode?Discipline=BIO&TestCode=CRP

  • 0
  • 0
  • 43
  • 1
  • 1

Answers

Class Rest.EmailSvc Extends %CSP.REST
{

XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
{
<Routes>
    <Route Url="/TesteQuery/" Method="GET" Call="TesteQueryString"/>
</Routes>
}

ClassMethod TesteQueryString() As %Status
{
    Set tSC = $$$OK
    
    If 'tSC Quit tSC       
    Set tProxy = ##class(%ZEN.proxyObject).%New()
    Set tProxy.Discipline = $Get(%request.Data("Discipline", 1))
    Set tProxy.TestCode = $Get(%request.Data("TestCode", 1))
    
    Set %response.ContentType = "application/json"
    set %response.Status = 200
    Do tProxy.%ToJSON()
    
    Quit tSC
}

}
 

And my Test

URL: http://localhost:57772/teste/TesteQuery/?Discipline=ssss&TestCode=ddd

Return:

{
	"Discipline":"ssss",
	"TestCode":"ddd"
}