API Rate Limiting with Upstash

By using Redis with Upstash we can keep a counter of requests by IP at the edge.

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

{
  "path": "/api/ping",
  "latency": null,
  "status": null,
  "headers": {
    "X-upstash-latency": "",
    "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.