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
{ S 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)
W response
Quit $$$OK
}
This is the response that I'm getting in Postman
But it says type is text not JSON
Thanks
Hi John, could you please tell me which class you are extending?
Try this
Set %response.ContentType = "application/json"
Thanks Rodolfo looks good now.
I thought that the fact I'm using write command (W response) , the response would always be text type ?
Thanks
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.