Created
October 15, 2021 18:27
-
-
Save ChristopherDavenport/0b2a799c5ea4b990b28a0a86aff6d39f to your computer and use it in GitHub Desktop.
Rate Limiting Agreements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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