All Products
Search
Document Center

Configure API

Last Updated: Sep 18, 2021

After registering an API (especially an HTTP API), you need to perform related configuration to use it. Only APIs in enabled state can be called. For HTTP APIs, you need to manually enable them.

About this task

You can complete the following configurations for an API:

  • Basic information: Set the API name, description, and access system. Different types of APIs have different attributes.
  • Advanced settings: Enable signature verification as required, and configure the ETag cache and timeout interval.
  • Header settings: MGS allows you to add or delete headers for all requests.
  • Traffic limit configuration: Set traffic limit for API calls.
  • Cache configuration: Cache API responses to reduce the business system pressure.
  • Parameter settings: Configure the request parameters and response type. This configuration is exclusive to HTTP APIs.

For more information about related parameters and configuration rules, click the links above.

Procedure

To configure an API, perform the following steps:

  1. Log in to the mPaaS console. In the left-side navigation pane, click Mobile Gateway Service.
  2. In the API list, click Configure in the Operation column of the target API. The API details page is displayed.
  3. In different API configuration areas, click Edit and edit the corresponding parameters. For more information, see Configuration information below.Configure1Configure2
  4. Click Save.

Configuration information

Basic information

Set the following parameters for HTTP API.

  • API name: The name of the API. This parameter is required and will be used for subsequent maintenance.
  • Description: The description of the API. This parameter is optional.
  • System: The business system to which the API belongs. This parameter is required.
  • Request path: The URL of the request. This parameter is required. You can enclose the path with${}, for example, /pets/${id}.
  • Calling method: This parameter is required. Valid values include: GET, POST, PUT, DELETE, and HEAD.
  • Message charset: This parameter is required. Valid values include: UTF-8 and GBK.

Advanced settings

  • Signature verification: Enable signature verification as required. If it is enabled, signatures in client requests will be verified.
  • Timeout period(ms): Set the API timeout interval, in ms. The timeout period settings sorted by priority are as follows: API timeout period > system timeout period > Default timeout period (3000 ms).
  • Open JSONP: Whether to allow cross-domain HTTP requests. JSONP allows the system to call APIs across multiple domains.

Header settings

MPS allows you to add or delete headers for all requests. In the Header settings area, click Modify to enter the edit mode. You can add or delete rules. Each rule contains four attributes: Location, Type, headerKey, and value.

  • Location: Valid values include request and response.
    • If you select request, a header will be automatically added to the request. The business system can obtain the header from MobileRpcHolder.
    • If you select response, a header will be automatically added to the response. The client can obtain the header from the response.
  • Type: Valid values include:
    • add: Add a header, which will overwrite the existing header (if any) in the original request.
    • delete: Delete a header. If this option is selected, value is optional. If value is set, the header will be deleted only when the specified value is matched.
  • headerKey: The value can be any string that complies with the RFC definition, except for headers exclusive to HTTP (such as host and content-Type) or exclusive to mPaaSGW (such as operation-Type).
  • value: The value can be any string.
Note: Don’t use underscores “_” when defining an HTTP header.

Traffic limit configuration

Traffic limit configuration includes traffic limit mode, traffic limit value, and traffic limit response:

  • Traffic limit mode
    • Disabled: API calls are not restricted.
    • Intercept: When the calls frequency exceeds the traffic limit value, the request is intercepted.
  • Traffic limit value
    Set a reasonable limiting threshold (in seconds) according to business requirements. When the traffic limit mode is Intercept and exceeds this value, the request will be restricted.
  • 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. }
    Among them,
    • 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.

Cache configuration

Cache API responses to reduce the business system pressure. For more information, see API cache.

Parameter settings

Note: This configuration only works on HTTP APIs. You do not need to configure parameters for APIs created through automatic import.
  • Request parameter settings

    • Parameter name: Required, the name of the parameter.
      Note: For Path, the parameter name must be consistent with that in the request path. For example, if the request path is /pets/${id}, then the Path parameter name should be id.
    • Parameter location: Required, it specifies whether the parameter is located in the path or query string.
    • Type: Valid values include: String, Int, Long, Float, Double, and Boolean. This parameter is required.
    • Default value: Optional, the default value of the parameter.
    • Description: Optional, the description of the parameter.
  • Response result

    • Response result type: Refers to the basic data type or custom data model.