Skip to main content

Extensibility and Integration

 

OutSystems

Consume a REST API

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 your application.
Start by looking into the REST API documentation 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).

Security

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

Define the REST API and REST API method using the information you found in the API documentation:

  1. In the Logic tab, open the Integrations folder;
  2. Right-click on the REST element and select Consume REST API...;
  3. In the displayed dialog, choose to add a single method (you can also choose to import all methods);
  4. Fill the information about the Method URL. You can add parameters in braces to the URL, which will result in the method’s input parameters;

    Examples:
    GET http://api.example.com/resources
    PUT http://api.example.com/resources/{id}

     
  5. If the REST API you are consuming requires authentication or specific headers, open the Headers / Auth tab and fill the needed information;
  6. Open the Test tab. If you added parameters to your Method URL, you’ll need to insert the parameter values to execute the test. For manipulation methods (as POST or PUT), fill the Request of the Body Content with the structure of the REST API you want to consume;

    Example of a request with JSON structure:
    {
          "Field1": "Value1",
          "Field2": "Value2",
          "Field3": "Value2"
    }
    
  7. 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. For this, click 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;
  8. Click OK.

In the Logic tab, open the Integrations folder and REST element. OutSystems does the following 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 platform's actions, with the same semantics as any action created by you in Service Studio.

You can now use the newly created method in your application the same way you use the remaining Server Actions:

  1. Go to the action flow where you want to use the REST API Method;
  2. In the Logic tab, open the Integrations folder and REST element;
  3. Open the REST API and drag the REST API Method into your action flow.

 

  • Was this article helpful?