@web/ratelimit
v1.0.0
MIT
.cap
✓ Verified by capdux.org
AI-First .d.cp
Official zero-heap fixed-slot sliding-window rate limiter plugin for cap:web
Install with Cap
$ cap add @web/ratelimit
AI Interface Stub .d.cp
// Type definitions for CP
import { App, AppMethod, Context, Response, Plugin, PluginScope } from "../../../../lib/web/app.cp";
export class RateLimitConfig {
max_requests: u32,
window_secs: u64,
key_header: string,
}
export class RateLimitDecision {
allowed: bool,
limit: u32,
remaining: u32,
retry_after: u64,
}
export class RateLimitSlot {
used: bool,
key_buf: [RATELIMIT_MAX_KEY_LEN]u8,
key_len: usize,
window_start: u64,
count: u32,
fn matchesKey(key: string): bool;
fn setKey(_: auto, key: string);
}
export class RateLimiter {
config: RateLimitConfig,
slots: [RATELIMIT_MAX_SLOTS]RateLimitSlot,
fn init(cfg: RateLimitConfig): RateLimiter;
fn reset(_: auto);
fn check(_: auto, key: string, now_sec: u64): RateLimitDecision;
}
export fn monotonicNowSec(): u64;
export fn formatU64(val: u64, out_buf: []u8): string;
export fn extractFirstToken(raw: string): string;
export fn setTestClock(now_sec: u64);
export fn resetGlobal();
export fn rateLimitHook(ctx: &mut Context): bool;
export fn createRateLimitPlugin(cfg: RateLimitConfig): Plugin;
export fn registerRateLimit(app: &mut App, cfg: RateLimitConfig): &mut App;
README
MarkdownNo README provided for this package version.
Version History
1 release| Version | Format / Size | Integrity (SHA-256) | Downloads | Published | Status |
|---|---|---|---|---|---|
| v1.0.0 | .cap · 4.0 KB | sha256-fd6a15abc59f909d… | 0 | 2026-11-26 | latest |