Making a GET request to custom cloud that returns JSON data

I’m working with a Photon and all I want to do is send a GET request to a cloud of my choosing. I know this cloud will return JSON data. I want to send the request and then parse the JSON. Searching through this forum I keep running into using HTTPClient on the Spark Core and I’m not sure if Spark.publish() essentially does a GET request. I’m new to firmware and need some guidance.

Hi @craigfoo

Spark.publish() sends an event to the Particle cloud and nothing is returned to your Photon. It does not do a GET request. The particle cloud can send that event on to you in a variety ways, in a browser, to a node JS program, to trigger a web hook in the cloud, etc.

Using the web hooks features of the Particle cloud, you could set it up so that event causes the Particle cloud to send a GET request to another host but I am not sure how you would get the JSON back. I think it should be possible to subscribe to that result–maybe @peekay123 who has used it more could say.

But using HTTPClient and a JSON parser on your Photon you could do this all with your own code and be in control of the process. That would be the direction that I would go in.

@bko, I think I keep leaning towards the HTTPClient/JSON parser route. Yeah, that’s what I’ll do…I guess. I need to up my firmware chops… :pensive:

@bko, using a webhook to send the GET to the a server and have it return a JSON payload is absolutely doable. The JSON data would be returned to the Photon using an event that the Photon subscribes to. The webhook can even do some parsing of that JSON response using Mustache and return the parsed results.

If the OP does not want to use the Particle Cloud whatsoever, then using HTTPClient and a JSON parser is the best solution. :smile:

1 Like

Thanks for the feedback @peekay123 and @bko, does anyone have any idea about my other question about HTTPClient?