API Rate Limiting with Vercel KV

By using Redis with Vercel KV, we can keep a counter of requests by IP address.

For the demo below, you can send a maximum of 5 requests every 10 seconds.

{
  "path": "/api/ping",
  "latency": null,
  "status": null,
  "headers": {
    "X-RateLimit-Limit": "",
    "X-RateLimit-Remaining": "",
    "X-RateLimit-Reset": ""
  },
  "data": null
}

The pattern we're using in this example is inspired by the GitHub API.