Quick start

Mocking provides a way out of external API dependencies. You can simulate the backend API to independently develop and debug a micro application on the frontend.

Mock file structure

├── mock
│   └── index.json File name cannot be changed.

Things to note

  • Mocking data is enabled by default. You can edit the examples as needed. Make sure to put all APIs within the api field.
  • The request path must be prefixed with /open-api or /custom-api. Otherwise, an API cannot be mocked.
  • A parameter must be enclosed with ${}. For example, in /open-api/login/${deviceId}/out, deviceId is a parameter.
  • The res field is the response that an API returns on receiving a request.
  • Mock will not be bundled into your application.

Data format

JSON

The mocked data is in JSON format.

FieldTypeNotes
mockbooleanSpecifies whether to enable mocking for all APIs.
apiApi[]Stores all the mocked APIs.

API

FieldTypeNotes
pathstringThe request path.
methodHTTP request methodsThe HTTP request method used in the request.
resObjectThe return parameter. The data structure is user defined. All the content in the res field is returned when you call the corresponding API.
mockbooleanSpecifies whether to enable mocking for this API.

Example:

{
"mock": true,
"api": [
{
"path": "/open-api/devices",
"method": "GET",
"res": {
"msg": "",
"success": true,
"data": [
{
"deviceID": "3342352342***",
"deviceName": "devicename1"
},
{
"deviceID": "1346456342***",
"deviceName": "devicename2"
},
{
"deviceID": "1342678742***",
"deviceName": "devicename3"
},
{
"deviceID": "1342352396***",
"deviceName": "devicename4"
},
{
"deviceID": "1342352966***",
"deviceName": "devicename5"
}
]
},
"mock": true
},
{
"path": "/open-api/login/${deviceId}/out",
"method": "POST",
"res": {
"msg": "",
"success": true,
"data": {}
}
}
]
}