Skip to content

Instantly share code, notes, and snippets.

@ChristopherDavenport
Created October 15, 2021 18:27
Show Gist options
  • Save ChristopherDavenport/0b2a799c5ea4b990b28a0a86aff6d39f to your computer and use it in GitHub Desktop.
Save ChristopherDavenport/0b2a799c5ea4b990b28a0a86aff6d39f to your computer and use it in GitHub Desktop.
Rate Limiting Agreements
// https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-ratelimit-headers
trait RateLimiter[F[_], K]{
def get(id: K): F[RateLimit]
def getAndDecrement(id: K): F[RateLimit]
def rateLimit(id: K): F[RateLimit] // Fails Request at this step, to be handled to 429 Too Many Requests and include a RetryAfter header
}
case class QuotaComment(token: String, value: Either[Long, String])
case class QuotaPolicy(limit: Long, timeWindowSeconds: Long, comments: List[QuotaComment])
case class RateLimitLimit(limit: Long, policy: Option[QuotaPolicy])
case class RateLimitRemaining(remaining: Long)
case class RateLimitReset(timeLeftInWindowSeconds: Long)
case class RateLimit(limit: RateLimitLimit, remaining: RateLimitRemaining, reset: RateLimitReset)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment