HTTP JSON接口模拟工具

一、简介

Interfake能简便地创建虚假的HTTP API,只需简单几行代码就可以创建模拟JSON接口(使用命令行方式也可以不写代码),不需要安装web服务器。Interfake是NodeJs开发的,是一款开源Mock Server工具。

二、以命令行方式使用 interfake

interfake 是NodeJs开发的,支持三种使用方式:JS代码方式、JSON配置方式和HTTP meta-API方式,本文选择不用写代码的、易读的JSON配置方式。JSON配置方式是按照interfake的配置格式将请求接口和返回内容保存到一个JSON文件中,再以命令行的形式启动interfake。

  1. 安装interfake
npm install request -g
npm install interfake -g
  1. 创建一个JSON配置文件 adventuretime.json
[
    {
        "request": {
            "url": "/hello",
            "method": "get"
        },
        "response": {
            "code": 200,
            "delay": 100,
            "body": {
                "say": "hello world!"
            }
        }
    },
    {
        "request": {
            "url": "/whattimeisit",
            "method": "get"
        },
        "response": {
            "code": 200,
            "delay": 100,
            "body": {
                "theTime": "Adventure Time!",
                "starring": [
                    "Finn",
                    "Jake"
                ],
                "location": "ooo"
            }
        }
    }
]
  1. 在命令行中启动interfake
interfake -p 3001 --file ./adventuretime.json
  1. 用浏览器打开测试一下
http://localhost:3001/hello
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值