RateLimiter
RateLimiter — a class for controlling the rate of requests to the Rest API. Singleton instance is available via the rest.rateLimiter property after Frame initialization.
Automatically limits the number of requests per second, queues requests when the limit is exceeded, and retries requests upon receiving an HTTP 429 error.
import { RateLimiter } from '@aspro-cloud/miniapp-jssdk'Properties
lastRequestTime
Timestamp (ms) of the last sent request
get lastRequestTime(): numberlimit
Maximum number of requests per second. The value is populated from the context on the first Rest API call via Rest.get() or Rest.post(). A value of -1 means the limit has not yet been received from the context
get limit(): numberprocessing
Number of requests currently being processed
get processing(): numberremaining
Number of remaining requests before reaching the limit. The value is updated upon receiving each Rest API response
get remaining(): numberreset
Timestamp (ms) after which the limit resets. The value is updated upon receiving each Rest API response
get reset(): numberMethods
getInstance
Returns the current singleton instance of RateLimiter
static getInstance(): RateLimiterdestroy
Removes subscriptions and releases resources
destroy(): voidExample
import { App, RateLimiter, Rest } from '@aspro-cloud/miniapp-jssdk'
await App.initializeFrame()
const rest = Rest.getInstance()
const rateLimiter = RateLimiter.getInstance()
// Get current user
const user = await rest.get('/core/user/get/')
// Read current rate limit values
console.log({
limit: rateLimiter.limit,
remaining: rateLimiter.remaining,
reset: rateLimiter.reset,
})const App = window.ACloudMiniApp
const frame = await App.initializeFrame()
// Get current user
const user = await frame.rest.get('/core/user/get/');
// Read current rate limit values
console.log({
limit: frame.rest.rateLimiter.limit,
remaining: frame.rest.rateLimiter.remaining,
reset: frame.rest.rateLimiter.reset,
});