Skip to content

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.

ts
import { RateLimiter } from '@flowlu/miniapp-jssdk'

Properties ​

lastRequestTime ​

Timestamp (ms) of the last sent request

ts
get lastRequestTime(): number

limit ​

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

ts
get limit(): number

processing ​

Number of requests currently being processed

ts
get processing(): number

remaining ​

Number of remaining requests before reaching the limit. The value is updated upon receiving each Rest API response

ts
get remaining(): number

reset ​

Timestamp (ms) after which the limit resets. The value is updated upon receiving each Rest API response

ts
get reset(): number

Methods ​

getInstance ​

Returns the current singleton instance of RateLimiter

ts
static getInstance(): RateLimiter

destroy ​

Removes subscriptions and releases resources

ts
destroy(): void

Example ​

ts
import { App, RateLimiter, Rest } from '@flowlu/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,
})
js
const App = window.FlowluMiniApp;

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,
});

Published under the MIT license.