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│ └── index.json File name cannot be changed.
api
field./open-api
or /custom-api
. Otherwise, an API cannot be mocked.${}
. For example, in /open-api/login/${deviceId}/out
, deviceId
is a parameter.res
field is the response that an API returns on receiving a request.The mocked data is in JSON format.
Field | Type | Notes |
---|---|---|
mock | boolean | Specifies whether to enable mocking for all APIs. |
api | Api[] | Stores all the mocked APIs. |
Field | Type | Notes |
---|---|---|
path | string | The request path. |
method | HTTP request methods | The HTTP request method used in the request. |
res | Object | The return parameter. The data structure is user defined. All the content in the res field is returned when you call the corresponding API. |
mock | boolean | Specifies 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": {}}}]}