When using a REST API, you can add logic to customize the information that is sent in the requests or received in the responses. For this, the following callbacks are available:
Use to modify the information of the original request, such as the URL, the request text or the headers.
Use to modify the information of the original response, such as the status code or the response text.
In these callbacks you can access the information from the original request or response, manipulate it and assign a modified value to the customized request or response.
An example of this kind of customization is when you are consuming a REST API that uses token-based authentication and you need to add the token to the URL before sending the request. In this situation you should use the OnBeforeRequest:
To customize the request before it is sent:
Set the On Before Request property of the REST API to
OnBeforeRequestaction. An action with the same name is made available under the REST API;
Double-click the newly created
OnBeforeRequestaction to edit it;
- Add your own logic to customize the request.
To customize the response after it has arrived:
- Set the On After Response property of the REST API to
OnAfterResponseaction. An action with the same name is made available under the REST API;
- Double-click the newly created
OnAfterResponseaction to edit it;
- Add your own logic to customize the response.
In the OutSystems Forge you can find several components providing an interface to third-party services using REST integration, such as the Box Connector or the JIRA Connector, where you can see in detail how the REST requests and responses are customized.