Question john.smith4237 · Sep 29, 2024

Response of JSON type

Hi Guys,

I'm using the below simple Get Webservice to return a JSON file, its working but the response is actually of Text type not JSON Type 

ClassMethod cmGetHomes(cnt1, cnt2) As %Status
{    response="{""Land"""_":"_""""_cnt1_""",""Home"""_":"_""""_cnt2_"""}"
 // set dataObj=##class(%DynamicObject).%FromJSON(response.data)
 //set response.data = dataObj
 //W response.%ToJSON()
 //set response.data = {}.%FromJSON(response.data)
 //set response.data = {}.%FromJSON(response.data)
 response
 Quit $$$OK
}

This is the response that I'm getting in Postman

But it says type is text not JSON 

Thanks

Product version: Ensemble 2018.1

Comments

john.smith4237  Sep 29, 2024 to Rodolfo Moreira dos Santos

 Extends %CSP.REST

0
john.smith4237  Sep 29, 2024 to Rodolfo Moreira dos Santos

Thanks Rodolfo looks good now.
I thought that the fact I'm using write command (response) , the response would always be text type ? 
Thanks

0
David Hockenbroch  Sep 30, 2024 to john.smith4237

When you're using a REST API, you're sending an HTTP or HTTPS response, so all of the typical HTTP headers apply. This includes the content type and the disposition header. The content type, as Rodolfo mentioned, can be set using %response.ContentType. Others can be set using %response.SetHeader.

0