Add a rate limiter
Allow one request to the reports route every 30 seconds and verify the 429 response.
Limit an expensive route
Save this profile as m4w.json in the application directory.
{
"listen": { "port": 9000 },
"protection": {
"endpoints": [
{
"paths": [
"/reports/*"
],
"methods": [
"GET"
],
"rate": {
"requests": 1,
"period_seconds": 30,
"burst": 1
}
}
]
}
}Start the server
php vendor/mini4work/webserver/examples/server.php m4w.jsonSend a request
curl -i http://127.0.0.1:9000/reports/daily
curl -i http://127.0.0.1:9000/reports/daily
curl -i http://127.0.0.1:9000/healthWith an initially full bucket, expect 200, then 429 with Retry-After. The health request still reaches the handler and returns 200.