This is a short introduction to get data over a HTTP/REST API into a Streamsheet.
As an example I build a Stream Machine to gather data from the OpenWeatherMap API. I chose this because it is a cool and free of charge API to access weather data for any location fairly easy. To build it yourself you will only require an account, which will provide you with an API Key. This API Key has to be inserted in the API call.
But first things first:
I wanted to build a Stream Machine which provides weather information on different cities depending on my input name.
I chose the current weather data API and found out, that the URL to be used in an API call has to look like this:
https://api.openweathermap.org/data/2.5/weather?q={city name}&appid={API key}
So implementing a Stream Machine to get the information of certain cities can be accomplished by replacing the placeholder through cities of my choice.
Connector and Producer:
To get information over a HTTP/REST call, I need to work with the HTTP.REQUEST (older versions call it REST.REQUEST()) function on a Streamsheet.
This function needs a Producer and a Connector.
Add the base URL in the Connector and define the Producer to take JSON as a data format (which is the data format of the arriving messages).
HTTP.REQUEST():
Subsequently open/create a Stream Machine and insert the HTTP.REQUEST() function.
Parameter of the HTTP.REQUEST() that have to be specified are the just created Producer, the URL extending from the Connector URL, the used method and the target.
Since my URL has to be adjustable, I´m using the CONCAT() function in C3 to add some flexibility. With D3 being the source of the city name.
=CONCAT("data/2.5/weather?q=",D3,"&appid={API Key}")
This way my URL will always be up to date with the city name provided in D3. Since I am only recieving information I choose “GET” as the Method.
INBOX() in the target parameter sets the location of the arriving data to the Inbox.
Finished. Now the current weather data will arrive in the Inbox depending on the city set in D3.
If you want drag & drop the values you are most interested in onto the grid.
Hint: A HTTP request is always a request/response action. The response will appear in the Inbox as soon as the server responded to your request.
Stream Machine:
To use this Stream Machine you have to insert your own API Key in C3.
Weather API Stream Machine.json (41.1 KB) v1.3