Render question

I’ve been playing with endpoints a little and am doing quite well with sending the data over to an app with asynchttpPost and processing the data sent, but the return path doesn’t seem to work the way my somewhat warped mind thinks it should.

Example:

void connectPing() {
    if(debugEnabled) log.debug "Ping received"
    jsonResponse(ping: "acknowledged")
}

void jsonResponse(retMap){
    retData = JsonOutput.toJson(retMap)
    if(debugEnabled) log.debug "$retData”
    render (contentType:'application/json', data:"$retData", status:200) 
}

I would expect that on the recieving end of this I would see

{“ping":"acknowledged"}

in the data section of the response header, but what I am seeing is something like:

[headers:[Transfer-Encoding:chunked, Date:Sat, 18 Dec 2021 11:50:39 GMT, Content-Type:text/html;charset=utf-8], warningMessages:[], class:class hubitat.scheduling.AsyncResponse, status:200, data:] 

So any thoughts about how to make it work the way I think it should?

Hmmmm.... There's someone I would suggest you speak to.... can't think who that would be.....

1 Like

I agree that is weird.... perhaps enclose the "ping: ackmowledged" in quotes and curly braces?

Found my problem(s), code below works

def connectPing() {
    if(debugEnabled) log.debug "Ping received"
    jsonText = jsonResponse([ping: "acknowledged"])
    render contentType: "application/json", data: "$jsonText", status:200
}

def jsonResponse(retMap){
    retData = JsonOutput.toJson(retMap)
    if(debugEnabled) log.debug "$retData”
    return retData
}

Doesn't look like the render was used as the response until I moved it back into the method defined by the mappings as the responding method.