Skip to main content

 

Extensibility and Integration

 

 

OutSystems

Simple Customizations

  • Edit
    Collaborate with us
    Edit this page on GitHub
  • When consuming a REST API, you can add logic to customize the information that is sent in the requests or received in the responses. Use the following callbacks for this purpose:

    OnBeforeRequest
    Use to modify the information of the original request, such as the URL, the request text or the headers.
    OnAfterResponse
    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.

    If you have an advanced integration scenario requiring .NET code to customize requests or responses, check Advanced Customizations.

    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.

    Using this simple customization method you can add HTTP headers and/or change their values, but you cannot remove existing headers. To remove HTTP headers you must use the OutSystems REST Extensibility API. Check Advanced Customizations for more information.

    Customize the request

    To customize the request before it is sent:

    1. Set the On Before Request property of the REST API to New OnBeforeRequest.

      An "OnBeforeRequest" action is made available under the REST API.

    2. Double-click the newly created action to edit it.

    3. Add your own logic to customize the request.

    Example use case: Adding a header for token-based authentication

    Consider a REST API that uses token-based HTTP authentication, requiring consumers to include an authorization token in an HTTP header. After importing this REST API to your OutSystems application, use the "OnBeforeRequest" callback to add a new header with the token.

    To build this example implementation we added the following steps in the callback logic flow:

    1. Add a local variable with "HTTPHeader" data type to the OnBeforeRequest callback action.

    2. Define a new HTTP header (name and value) using the local variable you created in the previous step.

      Example:
      Name = "Authorization"
      Value = "Bearer " + AccessTokenVar

    3. Add this header to the list of request headers using the "ListAppend" action. The current request headers are in the "Request.Headers" attribute.

    4. Set the "CustomizedRequest" output parameter to our changed "Request" using an Assign element.

    Customize the response

    To customize the response after it has arrived:

    1. Set the On After Response property of the REST API to New OnAfterResponse action.

      An "OnAfterResponse" action is made available under the REST API.

    2. Double-click the newly created action to edit it.

    3. Add your own logic to customize the response.

    • Was this article helpful?