All Products
Search
Document Center

Limit API traffic

Last Updated: Jul 16, 2021

Besides limiting the access to a specific API, MGS supports setting the API default traffic limit and the total traffic limit for the whole app to avoid the backend server from being overwhelmed during at request peak. If both the API default traffic limit and the app-level traffic limit are configured at the same time, they will be processed in order according to the limits, and the configuration with smaller limit will take precedence.

This topic describes how to set the API default traffic limit and the app-level traffic limit. To set the traffic limit for a specific API, you should go to the API detail page and set the limit in the Traffic limit configuration area. For more information, see Configure API.

Prerequisites

To use the traffic limit configuration, you must enable the API traffic limiting function on the Manage gateway page:

  1. Log in to the mPaaS console, and click Mobile Gateway Service on the left navigation pane.
  2. On the right of the page, click the Manage gateway tab, and switch Limit API traffic on.

API default traffic limit

Set default traffic limit for API, and the configuration will work on all APIs under the current app. The configuration works with following rules applied:

  • If you have already set a traffic limit on an API before you set the default traffic limit, then the traffic limit on the API shall be subject to the previous configuration.
  • The traffic limit for a specific API takes precedence over the API default traffic limit.
  • The default traffic limit still works on the APIs after it is modified.

Complete the following steps to configure the API default traffic limit:

  1. Turn the API default traffic limit switch on.
  2. In the default traffic limit setting area, click Edit to set the limiting information.
    • Default traffic limit: Set a reasonable limiting threshold (in seconds) according to business requirements.
    • Traffic limit response:
      The default response for traffic limiting is {"resultStatus":1002,"tips":"Too many customers, please wait for a moment"}.
      To customize the traffic limit response, use the following format:
           
      1. {
      2. "result": "==Fill in the customized response content here==",
      3. "tips": "ok",
      4. "resultStatus": 1000,
      5. }
    • result is customized response data in JSON format. The client only takes this field for processing when resultStatus is 1000.
    • tips is customized traffic limiting tips. If resultStatus is 1002, this field will be used to prompt the user.
    • resultStatus is the result code returned by limiting. For the specific meaning, refer to Gateway result codes.

Total traffic limit of the App

Set the total traffic limit of all APIs under the current app. Once the total limit of the app is exceeded, all API requests under the app will be restricted.

Complete the following steps to configure the API default traffic limit:

  1. Turn the Total traffic limit of the App switch on.
  2. In the default traffic limit setting area, click Edit to set the limiting information.
    • Total traffic limit: Set a reasonable limiting threshold (in seconds) according to business requirements.
    • Traffic limit response:
      The default response for traffic limiting is {"resultStatus":1002,"tips":"Too many customers, please wait for a moment"}.
      To customize the traffic limit response, use the following format:
           
      1. {
      2. "result": "== Fill in the customized response content here ==",
      3. "tips": "ok",
      4. "resultStatus": 1000,
      5. }
    • result is customized response data in JSON format. The client only takes this field for processing when resultStatus is 1000.
    • tips is customized traffic limiting tips. If resultStatus is 1002, this field will be used to prompt the user.
    • resultStatus is the result code returned by limiting. For the specific meaning, refer to Gateway result codes.