-
Notifications
You must be signed in to change notification settings - Fork 24
Quick Start: Add Quota
Adding a Quota using Volos.js is as simple as adding a few lines of YAML in your Swagger document!
- First, update your
package.json
file in your project to include thevolos-quota-memory":
module under
"dependencies": {
"express": "",
"a127-magic": "",
"volos-quota-memory": ""
}
Note: You can also use a quota implementation that uses Redis or Apigee as its provider. More information here.
-
Run,
$ npm install
. -
Execute
$ a127 project edit
to open up the Swagger editor. -
In the Swagger configuration file, under
x-volos-resources
, add the following to enable an in-memory quota provider named 'quota' that you refer to later:
quota:
provider: volos-quota-memory
options:
timeUnit: minute
interval: 1
allow: 2
- Finally, use
x-volos-apply
to apply this policy to the paths you want to enforce quotas on, referencing the resource you defined in the previous step:
paths:
/hello:
x-swagger-router-controller: hello_world
x-volos-authorizations: {}
x-volos-apply:
quota: {}
Now, try running the app as in the quickstart and try using the example curl command thrice:
$ a127 project start
$ curl http://localhost:10010/hello\?name\=Me
$ curl http://localhost:10010/hello\?name\=Me
$ curl http://localhost:10010/hello\?name\=Me
Error: exceeded quota<br> at...
The quota policy will only allow the first two requests per minute. From the third request onwards, you will get an error saying that the quota was exceeded.
Having Trouble? Try posting your question to the Apigee Community. Or, for more links and resources, check out our Help Page
Need help? Visit the Apigee Community ! |
---|
-
Getting started
-
Add policies to your API
-
Add security policies
-
Deploy your projects
-
Programmatic hooks
-
Good to know about
-
Deep dives
-
Reference topics
-
Troubleshooting and getting help
-
Related resources