I tried to API call using below logic inside a Task node.
I test using the Postman tool My File Response takes around 800ms. I applied different below logic and the Results inside a Task node For fetch response from API.
'First Logic
url = "http://MyAPIHost:port/API.json" rxfer.SetUrl(url) m.raw = rxfer.GetToString()
json = ParseJSON(m.raw)
'When I performed the First logic. Results are below :
When the Application launch :
'Second Logic
url = "http://MyAPIHost:port/API.json" rxfer.SetUrl(url) m.port = CreateObject("roMessagePort") rxfer.SetPort(m.port) rxfer.AsyncGetToString() m.msg = wait(3000,m.port) if m.msg = invalid then rxfer.AsyncCancel() else m.raw = m.msg.GetString() ?"m.raw : "m.raw end if json = ParseJSON(m.raw)
'When I performed the Second logic. Results are below :
When the Application launch :
Third Logic(Using Internal File):
m.raw = ReadASCIIFile("pkg:/api/API.json") json = ParseJSON(m.raw)
'When I performed the Third logic. Results are below :
When the Application launch :
I don't understand one thing. It's giving a Execution timeout error. It's ok but why Roku Device restart's the Automatic. Does any one knows about this issue?
You are not creating a roUrlTransfer object.
url = "http://MyAPIHostSort/API.json"
rxfer = CreateObject("roUrlTransfer")
rxfer.SetUrl(url)
m.raw = rxfer.GetToString()
json = ParseJSON(m.raw)
print json
I have already created the roUrlTransfer object. I wrote code in short for better visibility.