ratelimit
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v21View latest version
import { ratelimit } from "https://www.val.town/x/unkey/ratelimit/code/sdk.ts";
export default async function (req: Request): Promise<Response> {
const rl = await ratelimit({
identifier: "someone",
limit: 5,
duration: 60000,
});
if (!rl.success) {
return Response.json("back off", { status: 429 });
}
// Perform expensive operation here
return new Response("ok");
}