FREE OutSystems Workshops - Build an OutSystems App in 1 hour | ENROLL NOW

Tech Bites - How to integrate with a REST API

< Back to Blog

In OutSystems, it's possible to integrate with a REST API in order to call an external service.

First, a quick recap: a REST API is a web service provided by an agnostic technology somewhere over the internet. A web service has methods, and methods can be called and can have inputs. A call to a method has a response, which varies depending on the method's type. 

For this scenario, we want to get the current weather data into an OutSystems application. We need to find an external service provider such as to do that.

Here, it's required to have an account and generate an API key as a security measure to use the open weather services. 

We can now choose the service method that most fits our needs. In this case, the current weather service seems to do the trick.

So let's start!

In the Service Studio, go to the Logic tab, where you will find the Integrations folder. 

Right-click the REST option and select consume REST API.

There are two options to choose from: Add a single method or add multiple methods.  Since the latter needs a swagger file that we do not have or need at this point, let's use the first approach. 

We need to set the URL to call the service: let's get it from the website.

Notice that some optional inputs can be used, such as the units. We will add it manually to the call, using a similar syntax as for the other inputs.

Once you paste it, notice the words between curly brackets: those are input variables of this service method.

To test this service method call, we use the city name and the API key as inputs. Let’s provide values for the inputs: Lisbon as the city name and the previously generated API key from the website.

Once you click the test button, the response will appear below, and you can check the OK status returned by the service.

So, it seems like the call was executed successfully.

Next, you can check the elements that are part of the response and will be used by the platform to generate the required structures holding the response at runtime. Copy this code to the response body of the configuration window so that the platform can do its magic. 

After you click that button, finish the process, and the service is ready to be used. 

Notice all the structures created to allow the service to provide and hold its response.

How to use it? Call it like any other OutSystems action. 

Let's go ahead and call this method in a previously created screen.

Once we drag and drop the REST API method and define its inputs, we display the attributes' values on the screen.

So in this data action, we will set the city name to Lisbon and paste the API key again. These are the values used at runtime. 

After the call to the GetWeather service, just set the required outputs to later use on the screen. In this case, we will display the icon and the temperature, which are the outputs being set.

Then, we can use the icon URL described in the website documentation on the screen. 

Click the one-click publish button and open it in the browser. 

Now we can see information about the current weather that is coming from an external service. We are all set.

Turn Up Academy

Apply to our Turn Up Boot Camp

Senior Instructor

Latest Articles

‍What’s new in OutSystems Developer Cloud

‍What’s new in OutSystems Developer Cloud

Have you heard about the OutSystems Developer Cloud and want to know more about what's new and what the big benefits are? Then this article is for you!

Tech Bites - Should we validate form data on server-side?

Should we validate form data on server-side

When including forms in applications, developers often wonder if they need to re-validate data on the server side after having checked it on the client. Why go to the trouble of checking the data twice?

Tech Bites
The Top 5 Mistakes Handling Asynchronous Data In Outsystems Reactive Apps And How To Avoid Them

The Top 5 Mistakes Handling Asynchronous Data In Outsystems Reactive Apps

When developing an OutSystems reactive web app, you would expect to display data quickly, but it doesn't always happen. Do you know why? We'll explore the reasons and how to tackle them.