Tells if the current request is executed as a part of REST API call
Syntax
inRestAPI();
Arguments
No arguments
Return value
Returns true if current request is executed via REST API, returns false otherwise.
Sample code
In this example we will show you how to implement a very basic rate limiting for your REST API. We would assume that limit is set as number of requests per user per month and users table has two additional fields: ratelimitquota (the current number of requests) and ratelimit (the max allowed number of requests). The following code goes to AfterSuccessfulLogin event.
if( CommonFunctions.inRestApi() )
{
dynamic UpdatedData = XVar.Array();
dynamic WhereData = XVar.Array()
WhereData[ cUserNameField ] = username;
UpdatedData[ "ratelimitquota" ] = data["ratelimitquota"] + 1;
DB.Update( GlobalVars.cLoginTable , UpdatedData, WhereData );
if(data["ratelimit"] < UpdatedData["ratelimitquota"])
{
API.sendError( "Too many requests", 429 );
}
}