前言導讀

實際環境的需求可以說是:隻有你沒想到,沒有實作不了的,征對于目前實際開發、測試、生産等環境中,需要用到各類的接口可達幾十、甚至上百個,是以,必須需要一個統一管理的工具平台來統一管理這類接口,進而友善後續使用。
那麼今天來簡單介紹下開源的接口管理工具:YApi
平台介紹
官方網站:https://yapi.ymfe.org/index.html
Github位址:https://github.com/YMFE/yapi
YApi 是高效、易用、功能強大的 api 管理平台,旨在為開發、産品、測試人員提供更優雅的接口管理服務。可以幫助開發者輕松建立、釋出、維護 API,YApi 還為使用者提供了優秀的互動體驗,開發人員隻需利用平台提供的接口資料寫入工具以及簡單的點選操作就可以實作接口的管理。![]()
高效、易用、功能強大的 api 管理平台
特性
1、基于 Json5 和 Mockjs 定義接口傳回資料的結構和文檔,效率提升多倍
2、扁平化權限設計,即保證了大型企業級項目的管理,又保證了易用性
3、類似 postman 的接口調試
4、自動化測試, 支援對 Response 斷言
5、MockServer 除支援普通的随機 mock 外,還增加了 Mock 期望功能,根據設定的請求過濾規則,傳回期望資料
6、支援 postman, har, swagger 資料導入
7、免費開源,内網部署,資訊再也不怕洩露了
安裝環境介紹與布署
環境要求(centos安裝環境)
nodejs(7.6+)
mongodb(2.6+)
安裝 Node.js
[root@tools-server ~]# curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
[root@tools-server ~]# yum -y install nodejs
[root@tools-server ~]# yum install gcc-c++ make -y
安裝配置MogoDB資料庫
[root@tools-server ~]# cd /etc/yum.repos.d/
[root@tools-server yum.repos.d]# vim mongodb.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
[root@tools-server ~]# yum install mongodb-org -y
啟動服務
[root@tools-server ~]# service mongod start
Starting mongod (via systemctl): [ 确定 ]
[root@tools-server ~]# ps -ef|grep mongod
mongod 10549 1 0 11:00 ? 00:00:00 /usr/bin/mongod -f /etc/mongod.conf
root 10563 1291 0 11:00 pts/0 00:00:00 grep --color=auto mongod
[root@tools-server ~]# lsof -i :27017
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mongod 10549 mongod 8uIPv4 28721 0t0 TCP localhost:27017 (LISTEN)
建立資料庫
[root@tools-server ~]# mongo
MongoDB shell version: 2.6.12
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
> use yapi
switched to db yapi
> db.wong.insert({"name":"kenny wong"})
WriteResult({ "nInserted" : 1 })
> show dbs
admin (empty)
local 0.078GB
yapi 0.078GB
> db.addUser(\'yapi\',\'yapi321\')
WARNING: The \'addUser\' shell helper is DEPRECATED. Please use \'createUser\' instead
Successfully added user: { "user" : "yapi", "roles" : [ "dbOwner" ] }
安裝與配置YApi工具
安裝yapi軟體
[root@tools-server ~]# mkdir yapi
[root@tools-server ~]# cd yapi/
[root@tools-server yapi]# git clone https://github.com/YMFE/yapi.git vendors
如果下載下傳較慢,可直接下載下傳壓縮包進行解壓
[root@tools-server yapi-master]# cp config_example.json ../config.json
[root@tools-server yapi-master]# vim config.json
{
"port": "3000",
"adminAccount": "[email protected]",
"db": {
"servername": "127.0.0.1",
"DATABASE": "yapi",
"port": 27017,
"user": "yapi",
"pass": "yapi321"
},
"mail": {
"enable": true,
"host": "smtp.163.com",
"port": 465,
"from": "***@163.com",
"auth": {
"user": "***@163.com",
"pass": "*****"
}
}
}
[root@tools-server yapi-master]# npm install --production --registry https://registry.npm.taobao.org
啟動服務
WEB登陸
具體一些後面接口與項目操作,可以參考官方文檔