API mock

Updated at:

API mocking lets you simulate API responses without a live backend, so frontend and mobile development can proceed before the backend is ready.

Prerequisites

Before you begin, enable the API Mock switch:

  • Go to Manage gateway > Function Switch and turn on the API Mock switch.

Configure API mocking

  1. In the API list, find the target API, then click More > API Mock in the Operation column under the Manage APIs tab.

  2. On the Mock Configuration page, set the following parameters:

Parameter

Description

API Mock

Enable the switch to activate mocking for this API.

Hit rule

Only Percentage is currently supported.

Rule configuration

Enter a percentage from 0 to 100. This controls the proportion of incoming requests that receive the mock response.

Mock data

Enter the mock response body in the format below.

The mock response must follow this JSON structure:

   {
   "resultStatus": 1000,
   "tips": "ok",
   "result": "==Enter the mocked business data here=="
   }

Where:

  • resultStatus — the response code. For the full list of valid codes, see Gateway result codes.

  • tips — the response message.

  • result — custom response data in JSON format.

  1. Click Submit.

To verify the configuration, call the API and confirm it returns the mock response you defined.