Skip to content

A simple hello-world JSON API service that incorporates rate limiting via Nginx.

License

Notifications You must be signed in to change notification settings

rednafi/nginx-ratelimit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nginx-ratelimit

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.

Installation

git clone git@github.com:rednafi/nginx-ratelimit

Take it for a spin

  • 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"
    }