apiKey- The 32-character API key, unique to your OpenWeatherMap account.
city- The city which you want to retrieve the weather for. To reduce ambiguity problems with city names, it is better to use the city name and country. "San Francisco" could be 1 of 5 locations, so "San Francisco, US" will give much more specific results. To see the search results beforehand, you can check them here.
isMetric- Whether or not the temperature should be in metric (°C) or imperial (°F) units.
Remote IP- The first section of this request is
http://api.openweathermap.org, which is our endpoint. This is the value we put inside the
Remote IPAttribute. A couple of notes regarding this Attribute:
Remote Port- For the
Remote PortAttribute, this should be set to 80, which is the standard port for HTTP usage.
Method- Because we want to get data, the
MethodAttribute should be set to "GET".
Path- This is the specific path defined by the API provider. Usually, this is the text after the main root URL but before the
?character. In the case above, the path is
Authentication- This is used if the API requires a username and password, however OpenWeatherMap doesn't require this, so we set it to "None".
appidand needs to be used whenever attempting to retrieve data.
q=London. By looking at the documentation, you will see that the parameter
qis the "City name, state code and country code divided by comma".
unitsparameter should be set to "metric" or "imperial".
cityto build a Dictionary, which will form our
Queryinput socket of the HTTP GET Node, overriding any information in its
Bodyoutput (the response) into a Dictionary, we can use the new JSON Parse Node to convert the String. Because JSON can also be parsed as an Array, we need to tell Incari that we are expecting a Dictionary, not an Array. We do this by using the Conversion Node to cast the Any-type output of the JSON Parse Node to a Dictionary.
Responsevariable, we are getting another Dictionary called
main. From this, we are then able to get the temperature (
temp) as a Float. This structure (
temp) corresponds to the OpenWeatherMap documentation, which shows an example of the hierarchy of the API response.
Outputof the JSON Parse Node into the
Valueinput of a Dictionary-type variable (called
Responsein this case), it is possible to trigger Logic in several places whenever the value of that Variable is set. This Variable is then fed into a number of custom Functions to get the relevant key-value pairs and process them so that the text and images of the weather app change to reflect the API response.