rateLimit

fun OkHttpClient.Builder.rateLimit(permits: Int, period: Long = 1, unit: TimeUnit = TimeUnit.SECONDS): OkHttpClient.Builder(source)

Deprecated

Use the version with kotlin.time APIs instead.

An OkHttp interceptor that handles rate limiting.

This uses java.time APIs and is the legacy method, kept for compatibility reasons with existing extensions.

Examples:

permits = 5, period = 1, unit = seconds => 5 requests per second permits = 10, period = 2, unit = minutes => 10 requests per 2 minutes

Since

extension-lib 13

Parameters

permits

Int Number of requests allowed within a period of units.

period

Long The limiting duration. Defaults to 1.

unit

TimeUnit The unit of time for the period. Defaults to seconds.


Deprecated

Default rate limiting implementation is no longer provided. Source developers are now responsible for implementing their own rate limiting logic if desired, to prevent forks from bypassing it.

Replace with

this

An OkHttp interceptor that handles rate limiting.

Examples:

permits = 5, period = 1.seconds => 5 requests per second permits = 10, period = 2.minutes => 10 requests per 2 minutes

Since

extension-lib 14

Parameters

permits

Int Number of requests allowed within a period of units.

period

Duration The limiting duration. Defaults to 1.seconds.