Just dipping my toes into JSON. Noticed a few Kernel JSON utilities. What transmission methods are people using to send and receive JSON messages to external servers? I've mostly used HL7 messaging, so JSON syntax and transmission is new to me. --
--
http://groups.google.com/group/Hardhats
To unsubscribe, send email to Hardhats+u...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Hardhats" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hardhats+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hardhats/e825c85e-3625-42d5-8b71-12daa8c4ec4bn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hardhats/58eab772-e1f2-4d58-b31a-29d42e0c4202n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hardhats/58194c66-c795-4895-b326-aff61067cdb1n%40googlegroups.com.
Maybe I’m on the wrong track, but just in case you haven’t considered this. If you are using a relatively modern version of Cache, you can create a class that extends %CSP.REST. Note that I believe Yottadb/Octo has similar utilities. I created a very simple example shown below. It is loosely based on the samples.docserver class that comes with Cache. I created a simple global called ^AirMachines and I can send GET requests with curl (or just http from a browser) and get back data. The results formatting is based on the format requested. Note that the method ListOneAirMachine is written to return just text regardless of the call, but the other method, ListAirMachines, can return JSON if requested. I am a relative novice on Cache so someone with more experience can likely enhance this answer!
Class AirMachines.RESTServer Extends %CSP.REST
{
XData UrlMap [ XMLNamespace =
"http://www.intersystems.com/urlmap" ]
{
<Routes>
<Route Url="/AirMachines" Method="GET" Call="ListAirMachines"/>
<Route Url="/AirMachines/:recnum" Method="GET" Call="ListOneAirMachine"/>
</Routes>
}
ClassMethod ListOneAirMachine(recnum As %String)
{
#dim tSC As %Status =
$$$OK
#dim AX As %Integer = +$G(recnum)
IF AX'>0
D Q tSC
.W "<p>You must provide a valid numeric record number!</p>"
IF '$D(^AirMachines(AX))
D Q tSC
.W "<p>Record "_AX_" does not exist!"
W "<p>("_AX_") "_$P($G(^AirMachines(AX)),"^",1,6)_"</p>"
Q tSC
}
ClassMethod ListAirMachines()
As %Status
{
#dim tSC As %Status =
$$$OK
//#dim e As %Exception.AbstractException
#dim tNS As %String
#; If we have been asked for json
If $Get(%request.CgiEnvs("HTTP_ACCEPT"))="application/json"
{
#; Set the response header to JSON
Set %response.ContentType="application/json"
#; Create a JSON proxy
Set tProxy =
##class(%ZEN.proxyObject).%New()
#; And a list to hold the data
Set tList=##class(%Library.ListOfDataTypes).%New()
#; Add the data to the list
Set tNS=0
F SET tNS=$O(^AirMachines(tNS))
Q:(tNS'>0) D
.Set CallSign=$P($G(^AirMachines(tNS)),"^",1)
.I CallSign '="" D
..Do tList.Insert(CallSign)
#; Set the namespace property
Set tProxy.airmachines=tList
#; Output the JSON
Do tProxy.%ToJSON()
}
else
{
Set tNS=0
F SET tNS=$O(^AirMachines(tNS))
Q:tNS'>0
D
.W "<p>("_tNS_") "_$P($G(^AirMachines(tNS)),"^",1,6)_"</p>"
}
Quit tSC
}
}
And if you ask for this data in JSON: (ip address “redacted”)
curl -H "Accept:application/json" http://10.10.10.10:57772/AirMachines/AirMachines
{
"airmachines":["N9169U","N5016T","N9616F","N94296","N7648Q","N4426X","N174EH","N331SD","N222ES","N40VF","N14056"
]
}
Keep in mind that this does consume a Cache license.
From: hard...@googlegroups.com <hard...@googlegroups.com>
On Behalf Of Douglas Clayton
Sent: Thursday, July 28, 2022 9:18 PM
To: Hardhats <hard...@googlegroups.com>
Subject: [External] Re: [Hardhats] JSON message transmission
CAUTION: External email. Do not click links or open attachments unless you verify. Send all suspicious email as an attachment to Report Spam.
To view this discussion on the web visit https://groups.google.com/d/msgid/hardhats/82891e5d-e272-4423-b89d-06b6ab47af88n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hardhats/86d38b4c-4dcc-4b73-97ba-da0c3a188ad4n%40googlegroups.com.