Version: 3.0.9

Rate limiting your remotes

Your event or AsyncFunction may perform an intensive task that you don't want players to be able to invoke every second (and possibly crash your game)

A way you can get around this is by using the Net.Middleware.RateLimit middleware. This is a built in.

Limiting to a certain amount of requests#

The rate limiter middleware is created as such:

Net.Middleware.RateLimit({
MaxRequestsPerMinute: 1 // This can be the amount of requests you want to limit per minute
})

Then you pass it to a constructor for a server object, or a definition:

const Remotes = Net.Definitions.Create({
Example: Net.Definitions.AsyncFunction([
Net.Middleware.RateLimit({
MaxRequestsPerMinute: 1
})
])
})

Custom Error Handling#

When the rate limit is reached, it will run the error handler. By default this is set to a function which displays a warning on the server:

export function rateLimitWarningHandler(error: RateLimitError) {
warn("[rbx-net]", error.Message);
}

However, if you want to send this to something like analytics, you can provide your own error handler:

function analyticRateLimitError(error: RateLimitError) {
AnalyticsService.Error(error.Message); // this is just an example
}
const Remotes = Net.Definitions.Create({
Example: Net.Definitions.AsyncFunction([
Net.Middleware.RateLimit({
MaxRequestsPerMinute: 1,
ErrorHandler: analyticRateLimitError
})
])
})