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 inRestApi() then
Dim UpdatedData
Set UpdatedData = CreateDictionary()
UpdatedData("ratelimitquota") = data("ratelimitquota") + 1
DB_Update "users", UpdatedData, "username = '" & username & "'"
if UpdatedData("ratelimitquota") > data("ratelimit") then
API_sendError("Too many requests", 429)
end if
end if