npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ap-cli

v1.0.12

Published

mock server CLI

Downloads

22

Readme

ap-cli npm version Build Status NPM downloads

依据接口定义,帮助你快速的完成接口模拟工作。

主要功能:

  • [x] 通过json、js、swagger文件模拟接口数据
  • [x] 通过正则匹配指定需要mock的文件
  • [x] 生成简单markdown接口文档

目录

开始

下载ap-cli

$ npm install ap-cli -g

生成模板

$ ap-cli init data

data.json

[
  {
    "url": "/api/get/index",
    "method": "get",
    "response": {
      "name": "pc",
      "status": "success"
    }
  }
]

运行

$ ap-cli -m data.json

现在打开http://localhost:3000/api/get/index ,你会得到

{ "name": "pc", "status": "success" }

同时会在当前文件目录生成一个简单的markdown接口文档
json模板格式查看完整模板及说明

使用

  1. 通过js方式模拟数据

格式查看完整模板及说明

data.js
const getUserList = () => {
  const data = {
    "summary": "获取用户列表(get方式)",
    "url": "/api/get/userList",
    "method": "get",
    "parameters": "",
    "response": {
      "count": 100,
      "userList": []
    }
  }
  for (let i = 0; i < 100; i++) {
    data.response.userList.push({ id: i, name: `user${i}` })
  }
  return data
};

module.exports = {
  getUserList
};
运行
$ ap-cli -m data.js
查看接口

http://localhost:3000/api/get/userList

  1. 通过swagger文件模拟数据

这种方式主要是通过swagger生成一个xx_new.json文件,然后进行模拟数据

# 运行会生成一个swagger_new.json文件
$ ap-cli -s swagger.json
# 模拟数据
$ ap-cli -m swagger_new.json
  1. 通过正则匹配指定要模拟的文件

当前目录下有3个文件a1.json、a2.js、b1.js,你可以通过正则只模拟a1.json和a2.js文件的数据。

$ ap-cli -m all -r /^a/

CLI用法

|#|缩写|完整|默认|说明| |--|----|------|------|------| |1|-m|--mock [fileName]|'all'|模拟接口服务,[fileName]当前目录下要mock的文件名,[all]默认当前目录下的所有文件| |2|-r|--regexp [regexp]|无|通过正则匹配需要mock的文件| |3|-s|--swagger [fileName]|无|通过swagger生成json模板文件,[fileName]当前目录下的swagger文件名| |4|-p|--port [port]|3000|指定mock的端口|

完整模板及说明

不管是json、js、swagger文件,最终都是转换成下面的格式进行处理。

示例
[
  {
    "tags": "tags标签名",
    "summary": "获取用户信息接口json",
    "url": "/api/get/userinfo",
    "method": "post",
    "paramsTable": [
      "| 字段 | 类型 | 是否必须 | 说明 |\n",
      "|------|------|------|------|\n",
      "| id | string | 是 | 无 |\n"
    ],
    "parameters": {
      "parsing": true,
      "child": [
        {
          "key": "userid",
          "type": "string",
          "required": true,
          "description": "user id"
        }
      ]
    },
    "response": {
      "body": {
        "id": "0001",
        "status": "success",
        "userinfo": {
          "name": "pc",
          "age": 18,
          "gender": "boy"
        }
      }
    }
  }
]
主要属性说明

| # | 字段 | 类型 | 说明 | 默认 | 是否必须 | 备注 | |---|------|----|----|----|----|----| |1| summary | string | 接口概述 | xxx接口 | 否 | 无 | |2| url | string | 接口地址 | /api | 是 | 无 | |3| method | string | http请求方式 | get | 是 | 无 | |4| paramsTable | array | 接口请求参数md表格 | 无 | 否 | 无 | |5| parameters | / | 接口请求参数 | 无 | 否 | 可显示为表格(详见下1-1.parameters属性说明) | |6| response | / | 接口响应数据 | 无 | 是 | 无 | |7| tags | string | 接口文档名称 | 无 | 否 | 无 |

1-1. parameters属性说明

| # | 字段 | 类型 | 说明 | 默认 | 是否必须 | 备注 | |---|------|----|----|----|----|----| |1| parsing | boolean | 是否解析 | false | 否 | 无 | |2| child | object [] | 参数 | 无 | 否 | 无 |

更新日志

CHANGELOG