A simple rack middleware based rate limiter for REST and GraphQL.
brew install httpie
./start
http get :9393/users
http post :9393/users name="Ganesh Ganesh" email="me@itsgg.com"
http delete :#{PORT}/users
http post :9393/graphql query="query users { users { id, name, email } }"
http post :9393/graphql query="mutation CreateUser(\$name: String\!, \$email: String\!) { createUser(name: \$name, email: \$email) { id, name, email } }" variables:='{ "name": "Hello", "email": "hello@world.com" }'
http post :#{PORT}/graphql query='mutation DeleteUsers { deleteUsers { data } }'
Tweak the settings in gandalf.yml and try different operations like
http:
GET:
"/users":
limit: 1
period: 5
block_for: 5
POST:
"/users":
limit: 1
period: 5
block_for: 5
DELETE:
"/users":
limit: 1
period: 5
block_for: 5
graphql:
query:
users:
limit: 1
period: 5
block_for: 5
mutation:
createUser:
limit: 1
period: 5
block_for: 5
deleteUsers:
limit: 1
period: 5
block_for: 5
rake http:post
rake http:get
rake http:delete
rake graphql:post
rake graphql:get
rake graphql:delete
Example response
➜ rake graphql:get
http post :9393/graphql query='query users { users { id, name, email } }'
HTTP/1.1 200 OK
Content-Length: 385
Content-Type: application/json
X-Content-Type-Options: nosniff
{
"data": {
"users": [
{
"email": "chuck.medhurst@bode.co",
"id": 12,
"name": "Sheilah Hettinger DC"
},
{
"email": "chuck.medhurst@bode.co",
"id": 13,
"name": "Sheilah Hettinger DC"
},
{
"email": "isaac.collier@tromp-franecki.org",
"id": 14,
"name": "Estelle Feil"
},
{
"email": "isaac.collier@tromp-franecki.org",
"id": 15,
"name": "Estelle Feil"
},
{
"email": "pete.blanda@oconner.biz",
"id": 16,
"name": "Lorena Ondricka"
}
]
}
}
3:06AM gg rate-limit-plugin-example (master) ✗
➜ rake graphql:get
http post :9393/graphql query='query users { users { id, name, email } }'
HTTP/1.1 429 Too Many Requests
Retry-After: 20
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff