Connecting to REST data
Open Weather Map API
As an example we will use the Open Weather MAP API, this is a cloud service where you can look up the weather for certain locations. It is a great example of a REST cloud service as it uses many of the common patters you will find in other services.
You will find the Open Weather Map API here.
In most cases when accessing a REST cloud service you will need an API key, in this case you need to sign up and find the API key in the API keys section.
Take note of your API key as you will need it later.
REST services generally have an endpoint where you make your requests. This is nothing more than the base for all URLs you will use to fetch data from the service. The endpoint can usually be found in the documentation for the REST API, in our case the endpoint is:
The resource is generally what follows after the endpoint in the URL and in the REST pattern it should identify what you are trying to fetch or change (if it is a POST request).
In this guide we will try to fetch the forecast for a specified city, so we will use the /forecast resource. You can read more about the different resources available in the API documentation.
The REST node
When making request to a REST service it is a good idea to use the REST node. Start by creating a REST node and input the information we collected before.
The script we will use for the REST node is shown below, copy this into the script for the node replacing the template script that is in there by default:
Now the REST node will have both inputs and outputs correlating to the data needed in the request and available in the response. Now you can provide the API Key and the city, then send a signal to the Fetch input of the REST node and it will perform the request to the cloud service.
First the request function above will be called, this function will format the request using the inputs of the node.
When the response is received it will parse as specified in the response function above and set the outputs of the node.
Once you have the REST node working it is a good pattern to create a component that contains the node so you don't have to repeat this work, or copy and paste the REST node. So if you need to change something in the request you only need to do it in one place.
This is just the basics of the REST node, with it you can expose cloud services and data to designers and developers in a great way to make it easy to design prototypes and experiments on live data.