Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Quick Start: Add Quota

jwest-apigee edited this page Sep 4, 2014 · 17 revisions

Adding a Quota using Apigee-127

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 the volos-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> &nbsp; &nbsp;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.

Clone this wiki locally