Please read Part 1 of this series before continuing with this article.
Creating a Function to get Weather Data
Add new connector function and edit
Name the function / Define Inputs
Give the function a descriptive name, this will be used in the Tulip App Builder.
Add an input - for our app we will allow the user to choose a city name to see weather data for that city. That means we will need city_name as an input for our function. You can use whatever name you'd like.
This is where you choose the specific information to use in your app. Outputs can be named whatever you would like. In this case we are using current_temp and main_description.
Define the Endpoint and Query Parameters
The endpoint and query parameters are specific to the API that you are using. In this case we will use /data/2.5/weather as the endpoint path. For query parameters, we will need q to define the city and APPID to define the developer key for openweathermap.org. Reference the API documentation for details and definitions for the query parameters. This will be different for each API.
Set values for API Keys:
- Type $city_name$ to use the previously defined input variable
- Enter you unique APPID (provided by openweather.org)
Map the Tulip Output Variable to API Path
In the Response Section, choose an output variable that you defined above and enter the path for the data returning from the API. For example, the Output variable current_temp will have a Path of main.temp. Repeat this process for all outputs.
NOTE: Tulip supports XML and JSON data formats. In this example we are using JSON. Every API will return data in a different format. We recommend using tools such as Postman to better understand the format of your data before attempting to connect to Tulip.
That's it, you have successfully created a Tulip connector function that can retrieve data from a RESTful API!
Continue to Part 3 to use this function in an App.