OutSystems Platform allows running logic before executing each request of an exposed REST API.

For that, do the following:

  1. In the REST API, set property ‘On Request’ to ‘New OnRequest’;
  2. Open the ‘OnRequest’ callback (that now is available under the REST API);
  3. Implement the logic to preprocess the request.


In this example we have a Contacts application to manage people contacts. It exposes a REST API. To avoid over usage, we want to limit the number of requests a client can do per day. We’ll do that by preprocessing the request before it is executed.

In ContactsAPI, go to property 'On Request' and select ‘New OnRequest’. This makes the OnRequest callback available.

Implement the OnRequest logic to limit the number of requests coming from the same client IP:

  1. Implement a user action with logic to limit the daily number of IP requests:

CheckRequestsLimitByIP(IP Text): boolean

  1. Create a user exception:


  1. Implement the logic of the OnRequest flow:

Some notes about the flow:

    1. In the If condition, use function GetIP from extension HttpRequestHeader. Learn how to add dependencies;
    2. When raising the error, set the message with: "You have reached your limit of requests per day."

From now on, clients that reach their daily limit of requests, will start receiving the following response:

{"Errors":["You have reached your limit of requests per day."],"StatusCode":500}

See also

Expose Data Using REST | Exposed REST API Method Properties