Skip to main content

Extensibility and Integration

 

OutSystems

REST API Structures

When you consume REST API methods in your module, OutSystems automatically creates the Structures that define the information hold by the input and output parameters. The name of each Structure is generated from:

  • The HTTP Request type;
  • The method name;
  • If it will hold a Request or a Response.

The data type of each input or output parameter is mapped into an OutSystems data type.

The following example consumes a REST API Method from Twitter:

HTTP Request type: POST

URL: https://api.twitter.com/1.1/account/settings.json?lang={mylanguage}

Response:
{
"use_cookie_personalization" : true,
"language" : "en"
}

The following Structure would be automatically created for this method:

Reuse of Structures

Whenever you add a new REST API method or modify an existing one, OutSystems checks for existing Structures that can be reused to define the information hold by the new input and output parameters. This minimizes the number of Structures in your module. 
A new Structure is not created and an existing one is reused instead if between them:

  • All attributes with the same name have the same or compatible type;
  • More than half of the new attributes are covered.

When an existing Structure is reused, it might need to undergo some changes in order to comply with the different methods where the Structure is used. For example, the Structure name might need to change and new attributes are added. The methods in your module already using that Structure won’t be impacted by those changes.

Reusing a Structure Example

Considering the previous Twitter’s REST API example, we will now add the GetSettings method of the same REST API, keeping only some relevant response parameters:

HTTP Request type: GET

URL: https://api.twitter.com/1.1/account/settings.json

Response:
{
"use_cookie_personalization" : true,
"language" : "en",
"always_use_https" : true
}

As the existing PostSettingsResponse Structure is compatible with the new method, the Structure is reused. The following changes take place:

  • The Structure is renamed to Settings to matches both methods where it is used;
  • An additional attribute is added to the Structure.

Creating a New Structure Example

The following example adds a larger number of parameters to the Response example of the GetSettings method and removes one parameter that was already there:

{
"language" : "en",
"always_use_https" : true,
"discoverable_by_email" : true,
"screen_name" : "theSeanCook",
"show_all_inline_media" : false,   
"geo_enabled" : true,
"protected" : false
}

As only three of the attributes are covered by the existing Structure, which is less than half of the attributes, the existing Structure can’t be reused. A new Structure named Setting is created to hold the GetSettings method's Response:

The previous Settings structure is not deleted, as it is still used by the PostSettings method.

 

  • Was this article helpful?