Add Plugins
Last updated
Was this helpful?
Last updated
Was this helpful?
Any API Definition can make use of plugins. A plugin is a way to add functionalities to your definition, like rate limit, CORS, authentication, etc...
In this tutorial we will add a plugin to our definition.
Let's create a file called rate_limit.json
with our new additions to the API definition. We will create a rate limit rule that we can only send 5 req/m
just for us to play around with it.
Now lets update our API definition:
http -v PUT localhost:8081/apis/my-endpoint "Authorization:Bearer yourToken" "Content-Type: application/json" < rate_limit.json
curl -X "PUT" localhost:8081/apis/my-endpoint -H "Authorization:Bearer yourToken" -H "Content-Type: application/json" -d @rate_limit.json
Done! Now Janus already reloaded the configuration and the rate limit is enabled on your endpoint.
Lets make a few requests to our endpoint and see if the rate limit is working.
You should see a few extra headers on the response of this request:
This means the plugin is working properly. Now lets make the same request 4 more times... On the fifth time you should get:
After 1 minute you should be able to make 5 more requests :)
http -v GET
curl -X "GET"
In the we'll learn how to protect our endpoint.