I’ve got a couple of questions about webhooks I’ve been struggling to find the answer for.
The first, is that if the data is split up into more than one response, how do you know when it is finished and you have all the data? Is it best to check the size of the response or just see if ‘}’ is the last character?
The second is about testing via a CLI while I’m getting the template and other options correct. If I use:
Rather than just the output, I get over 24k of data back, with the JSON I requested repeated many times. Is there a way to trigger a webhook and just see a single response?
I’m busy trying to learn about the webhook filterings to reduce the amount of data sent, but currently the returned JSON returns two responses. If I’m going to parse the JSON, I need to stick the two bits together first. Is there any data that is sent in the webhook responses that says this is the last chunk?
Not that I know of, since the cloud also doesn't know how long the remote server will keep sending responses back and when it's done sending.
Typically your code should know what it requested and how to determine when all the expected data has been received completely (e.g. the JSON root object gets closed).
After all the Particle cloud is only the "delivery man" and has no knowledge about the data in itself - usually the sender and recipient have.
Thanks, that makes sense. It look like 512 is a max chunk size, so I’ve got two ways of dealing with it. One is to assume that if the returned data is 512 and does not end in ‘}’, then there is probably more to come. Or just keep a count of { and }, then assume when they match the data is done.
You can also expect the full response to be delivered within a finite amount of time.
When you are not getting a new partial response within some short period after the last I’d assume it’s save to conclude you already got it all.