目录

  • 一、前后置操作
  • 1.1 提取变量
  • 1.2 接口间相互传递数据
  • 二、 Moc数据
  • 2.1 定义入参
  • 2.2 定义返参
  • 2.3 本地Mock
  • 2.4 高级Moc

一、前后置操作

1.1 提取变量

登录接口提取返回数据里的token,保存为全局变量

apifox日常使用_数据

1.2 接口间相互传递数据

详情接口使用登录接口返回提取的token

apifox日常使用_传递数据_02

二、 Moc数据

2.1 定义入参

apifox日常使用_自动生成_03

2.2 定义返参

通过json生成

apifox日常使用_自动生成_04


apifox日常使用_传递数据_05

设置自动生成返回数据的规则

apifox日常使用_自动生成_06

如data中返回2组对接

apifox日常使用_传递数据_07

数组中随机返回其一

apifox日常使用_传递数据_08

2.3 本地Mock

本地Moc请求数据 (也可以选择云端Moc数据)

apifox日常使用_自动生成_09

或者

apifox日常使用_自动生成_10

2.4 高级Moc

可以定义不同的入参返回不同的数据

apifox日常使用_自动生成_11

{
        "data": [
            {% for i in range(0, 20) -%}
            {
                "_id": {{i}},
                "url": "@image('200x200', '#FF6600')",
                "author": "@cname",
                "type": {% mock 'pick', '["cat","dog"]' %},
                "source": "淘宝",
                "content": "颜值特别高,灰色的毛毛看着特别可爱"
            },
            {%- endfor %}
        ],
          "errCode": 0,
  "errMsg": "查询成功,请勿商用,以免造成侵权。",
    "author": "接口管理员:B站咸虾米",
  "timeCost": 42
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.

效果:

apifox日常使用_数据_12

更多参考文档
 https://apifox.com/help/api-mock/intro-to-mock

视频教程
 https://www.bilibili.com/video/BV1fa4y1C79o/?spm_id_from=333.788&vd_source=a68414cd60fe26e829ce1cdd4d75a9e6

[Haima的博客]