A simple hello-world JSON API service that incorporates rate limiting via Nginx. It allows 50 requests per second and returns a 429 error when the limit is exceeded.
See the blog post here.
git clone git@github.com:rednafi/nginx-ratelimit
-
Start the service:
docker compose up -d
-
Test the rate limiting by sending many requests:
seq 200 | xargs -n 1 -P 100 bash -c 'curl -s localhost/greetings|jq'
This returns:
{ "message": "Hello World" } { "message": "Hello World" } ... { "status": 429, "message": "Too Many Requests" } { "status": 429, "message": "Too Many Requests" } { "message": "Hello World" } { "status": 429, "message": "Too Many Requests" }