Interface RateLimit

All Superinterfaces:
org.teavm.jso.JSObject

public interface RateLimit extends org.teavm.jso.JSObject
A rate limiting binding. Declared with rateLimit(), named RATELIMIT by default.

The limit and period come from the Wrangler configuration rather than from the call, so this surface is one question: has this key had its allowance.

Counting is per colo rather than global, so the effective limit across the network is higher than the configured one.

 if (!env.rateLimit().allow(request.getHeaders().get("cf-connecting-ip"))) {
 	return Bytebox.response("slow down", 429);
 }
Since:
1.0.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Whether a key was within its allowance.
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    Consumes one unit of a key's allowance.
    org.teavm.jso.core.JSPromise<RateLimit.Outcome>
    limit(TSObject options)
     

    Methods inherited from interface org.teavm.jso.JSObject

    cast
  • Method Details

    • allow

      default boolean allow(String key)
      Consumes one unit of a key's allowance.
      Parameters:
      key - what to count against, such as an IP or a user id
      Returns:
      whether the request is within the limit
    • limit

      org.teavm.jso.core.JSPromise<RateLimit.Outcome> limit(TSObject options)