An overview of

1.1 yapi

YApi is an efficient, easy-to-use and powerful API management platform, which aims to provide more elegant interface management services for development, product and test personnel. YApi can help developers easily create, publish, and maintain apis. YApi also provides users with excellent interactive experience. Developers only need to use the interface data writing tool provided by the platform and simple click to manage the interface. Unified management and maintenance of API, multi-person collaboration, support the original API one-click import and API document export. The request parameters of the previous API or corresponding parameters can be used as the request parameters of the next API, supporting one-key automated testing, greatly improving work efficiency.

1.2 the flow chart

1.3 features

  • The structure and documentation of the data returned based on the Json5 and Mockjs definition interfaces is many times more efficient
  • The flat permission design not only ensures the management of large enterprise-level projects, but also ensures the ease of use
  • Postman-like interface debugging
  • Automated tests that support assertions on Response
  • In addition to supporting normal random mocks, MockServer has added the ability to mock expectations, which return expected data based on set request filtering rules
  • Support for Postman, HAR, Swagger data import
  • Free open source, Intranet deployment, information is no longer afraid of leakage

1.4 Environment Requirements

  • Nodejs (+ 7.6)
  • Directing (+ 2.6)
  • git

The second deployment

2.1 the node deployment

Yum -y install git CD/data/software && wget HTTP: / / https://npm.taobao.org/mirrors/node/v10.16.2/node-v10.16.2-linux-x64.tar.xz Tar -xf node-v10.16.2-linux-x64.tar.xz mv node-v10.16.2-linux-x64 node#Change the permission to root
chown root.root node -R
cat > /etc/profile.d/node.sh << EOF
export PATH=$PATH:/data/software/node/bin
EOF
source /etc/profile.d/node.sh

node -v
Copy the code

2.2 directing installation

The cat > / etc/yum. Repos. D/mongo. '< < EOF [mongo - org - 4.0] name = directing a Repository baseurl=https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/4.0/x86_64/ gpgcheck = 0 enabled = 1 EOF yum clean all && yum makecache yum -y install
#Configure paths
mkdir -pv /data/mongod
chown mongod.mongod /data/mongod
/etc/mongod.conf 
storage:
  dbPath: /data/mongod
  
#Start the
systemctl start mongod
systemctl enable mongod
Copy the code

2.3 yapi deployment

Deploying the YAPI platform is very easy using the YapI-CLI tool we provide. Execute yAPI Server to start the visual deployment program, enter the appropriate configuration, and click Start Deploy to complete the entire site deployment. After the deployment is complete, run node/{website path /server/app.js} to start the server as prompted. Open the specified URL in the browser, click Login, enter the administrator email you just set, the default password is ymfe.org login system (default password can be changed in the personal center).

  • The deployment of
npm install -g yapi-cli --registry https://registry.npm.taobao.org
yapi server 
Copy the code
  • Web Interface Deployment

Because it was under the cloud router, the mongod password was not set

The dependency library installation is complete. Initializing the mongodb database...> [email protected] install-server /data/my-yapi/vendors > node server/install.jslog: mongodb load success... The administrator account is successfully initialized. The account name is "[email protected]" and the password is "ymfe.org". The deployment is successful. The "node Vendors /server/app.js" instruction starts the server, and then access it in your browser by opening http://127.0.0.1:9009Copy the code
  • upgrade
CD {project directory} yapi ls // View the Version list. Yapi update // Update to the latest Version. Yapi update -v {Version} // Update to the specified VersionCopy the code

2.4 Pm2 daemon process

npm install pm2 -g
[root@devops-yapi my-yapi]# pm2 start "vendors/server/app.js" --name yapi
[PM2] Starting /data/my-yapi/vendors/server/app.js infork_mode (1 instance) [PM2] Done. ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ App name │ Id │ version │ mode │ PID │ status │ restart │ uptime │ CPU │ mem │ user │ watching │ ├ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┤ │ yapi │ │ 0 1.8.1 │ fork │ online │ 0 │ 0s 0% │ 14.1 MB │ root │ disabled │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ Use ` pm2 show  <id|name>` to get more details about an app [root@devops-yapi my-yapi]# pm2 info yapiDescribing the process with id 0 - name yapi ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ status │ online │ │ name │ yAPI │ version │ 1.8.1 │ restarts │ 0 │ uptime │ 24s │ script path │ restarts / data/my - yapi/vendors/server/app. Js │ │ script args │ N/A │ │ errorlogPath │ │ ├ ─ /root/.pm2/logs/ yapi-error-log │ outlogPm2 /logs/yapi-out.log │ │ pid path │ root/.pm2/pids/yapi-0.pid │ interpreter │ node │ interpreter Args │ N/A │ script ID │ 0 │execCWD /data/ my-yAPI │ │execMode │ fork_mode │ node.js version │ 10.16.2 │ │ node env │ N/A │ watch & reload │ - │ unstable restarts │ 0 │ │ restarts │ Created at │ : the 2019-08-12 T11 35:02. 441 z │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ Actions available ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ km: heapdumps │ │ km: CPU: profiling: start │ │ km: CPU: profiling: stop │ │ km: heap: : from the start │ │ km: heap: from: stop │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ Trigger via: Value ┌ pm2 trigger yapi < action_name > Code metrics ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ Heap Size 36.80 MiB │ │ │ Heap Usage │ 81.39% │ │ Used Heap Size │ 29.95 MiB │ Active requests │ 0 │ Active handles │ 10 │ Event Loop 0.51 ms Latency │ │ │ Event Loop Latency p95 49.22 ms │ │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ Divergent env variables  fromlocal env 


 Add your own code metrics: http://bit.ly/code-metrics
 Use `pm2 logs yapi [--lines 1000]` to display logs
 Use `pm2 env 0` to display environement variables
 Use `pm2 monit` to monitor CPU and Memory usage yapi
Copy the code

Three USES

3.1 Project/Group creation

Start by creating a project. You can create multiple groups within a project and add members to them

3.2 Data Import and Export

Supports Postman collection import and Swagger data synchronization

3.3 Environment Configuration

You can create multiple environments with common parameters or domain names, and the parameterized mode is easy to switch

3.4 Interface Usage

  • Sending the request requires the plug-in to be installed

  • Send a GET request

  • Sending a POST request

3.5 Automated Testing

Once the interface tests are complete, they can be saved as test collections for automated testing

You can automate the test by params for the first interface, or params for the second interface with the body in response

Assertions can be written in tests

You can see the test report for each interface

Server side testing is to run the request on the server

3.6 interface mock

Four reflection

Personally, I think the tool is still a good tool. The following is only a personal evaluation of the tool used in work, for reference only.

4.1 the advantages

  • This tool is simple and convenient, the flat permission management project/group is convenient and quick multi-person collaboration interface test, reduce the front and back end interface docking cost, break the front end to rely on the back end interface bondage
  • Automate tests and mock parameters with comments/wikis, export interface documentation, unify document format, no additional maintenance interface
  • Interface changes, interface documents are updated through testing, unified platform management does not need to maintain and update multiple documents
  • Web deployment is convenient and quick

4.2 disadvantages

  • The response to the interface request cannot be recorded. If the response of the interface can be recorded, it will be easier to view
  • For interfaces with callbacks, consider configuring callbacks on the server side to accommodate a wider range of scenarios

5 reference Links

  • Yapi website

  • Use YApi to manage API documentation, tests, and mocks

  • Automatically updates Swagger interface data to the YApi platform

  • Automated testing