Now we can test that each rate limiting tier is working as expected by sending a series of HTTP requests (for example, six for Free Tier and seven for Basic Tier) to the endpoint with the appropriate API key with the goal of exceeding the configured rate limit for that tier. The tests wait for one second between requests to avoid overwhelming the server and test rate limits more clearly.
Test the rate limiting of the Free tier:
for _ in {1..4}; do
curl -i $KONNECT_PROXY_URL/anything \
-H "apikey:amal"
echo
done
for _ in {1..4}; do
curl -i http://localhost:8000/anything \
-H "apikey:amal"
echo
done
On the last request, you should get a 429
response with the message API rate limit exceeded
.
Test the rate limiting of the Basic tier:
for _ in {1..6}; do
curl -i $KONNECT_PROXY_URL/anything \
-H "apikey:dana"
echo
done
for _ in {1..6}; do
curl -i http://localhost:8000/anything \
-H "apikey:dana"
echo
done
On the last request, you should get a 429
response with the message API rate limit exceeded
.
Test the rate limiting of the Premium tier:
for _ in {1..11}; do
curl -i $KONNECT_PROXY_URL/anything \
-H "apikey:mahan"
echo
done
for _ in {1..11}; do
curl -i http://localhost:8000/anything \
-H "apikey:mahan"
echo
done
On the last request, you should get a 429
response with the message API rate limit exceeded
.