Enabling local throttling

Local rate limiting can be enabled by adding rate limiting policies, which is defined in the policies.yaml file, to the OpenAPI definition. A rate limiting policy can be specified for a resource or an API using the x-wso2-throttling-tier OpenAPI extension. You need to define the policy (or policies) in the policies.yaml file, which is in the <MGW-project> directory. A set of policies are available by default. However, you can add custom policies to the file and refer to them by name via the OpenAPI definition. If you simultaneously define a throttling policy at the API level and the resource level, the API level policy will be applied as the API level policy will override the resource level policy.

The following sub sections explain as to how you can work with OpenAPI extensions to add custom API level and/or resource level throttling policies.

Defining a throttling policy for local throttling

WSO2 API Microgateway allows users to define,

  • Resource policies
  • Application policies
  • Subscription policies

in the policies.yaml file which is in the <MGW-project> directory.

The following is a sample on how you can define a throttling policy named 10kPerMin in the policies.yaml file.

Defining a throttling policy

- 10kPerMin:
    count: 10000
    unitTime: 1
    timeUnit: min

Adding an API level throttling policy

API level throttling policy

x-wso2-basePath: /petstore/v1
x-wso2-throttling-tier: 10kPerMin
     - https://petstore.swagger.io/v2

Adding a resource level throttling policy

Resource level throttling policy

      - pet
      summary: Finds Pets by status
      description: Multiple status values can be provided with comma separated strings
      operationId: findPetsByStatus
      x-wso2-throttling-tier: 10kPerMin

For more information, you can find a sample OpenAPI definition with policies applied from here .