When you need to retrieve or manipulate information from another system, and
that system provides REST APIs for that effect, you can consume a REST API in
Start by looking into the documentation of the REST API you want to use and understand how it works. You will need to gather the following information:
- Base URL;
- Security / Authentication requirements;
- Methods definition (HTTP Method, URL Path, response format).
Each REST API will have their own model of security and authentication process, which may imply the creation of an account, the registration for an API key or the usage of tokens. To consume a REST API in OutSystems you must understand and follow the provider’s security model.
Define the REST API and REST API Method
After gathering all the information you need from the REST API documentation, do the following to consume a method of the REST API:
- In the Logic tab, open the Integrations folder;
Right-click on the REST element and select Consume REST API...:
In the displayed dialog, choose to add a single method:
If the REST API you want to consume is compliant with the Swagger specification, you will be able to add all the API methods in one step by choosing ADD ALL METHODS. Otherwise, you need to add each method individually.
Fill the information about the Method URL. You can include parameters in braces in the URL for the method’s input parameters;
If the REST API you are consuming requires authentication or specific headers, open the Headers/Auth tab and fill the needed information:
Fill the information about the Request and the Response. The easiest way to do this is to perform a test to the API and use the test result - alternatively, you can add the JSON structure or plain text example directly in the Request and Response fields in the Body tab. Open the Test tab. If you have parameters in your Method URL, you need to insert the parameter values to execute the test:
For manipulation methods, such as POST or PUT, fill the Request of the Body Content with the corresponding request structure:
Click Test. If the test is successful, you will see the method’s response in the Response area of Test tab.Use that information to fill in the Response in the Body tab by clicking COPY TO RESPONSE BODY in the Response area. Leave only the needed fields. For manipulation methods (such as POST or PUT), do the same for the Request, by pressing COPY TO REQUEST BODY in the Request area:
Usually, the most common fields are obtained this way. To know in full detail all the available fields, check the API documentation;
Check if the Request and Response information is correct in the Body tab and click OK:
At this point, check what OutSystems does automatically for you:
- Creates the REST API;
- Creates the REST API Method with the corresponding input and output parameters;
- Creates the Structures to hold the corresponding input and output parameters;
- Maps the REST Data Types into OutSystems Data Types.
Use the REST API Method in your Application
OutSystems translates the methods exposed by a REST API into OutSystems actions, with the same semantics as any action created by you in Service Studio.
You can now use the newly created methods in your application the same way you use the remaining Server Actions:
- Go to the action flow where you want to use the REST API Method;
- In the Logic tab, open the Integrations folder and REST element;
Open the REST API and drag the REST API Method into your action flow:
Use the method's output parameters as you do for any other action: