头图
As a back-end developer, we often need to maintain API documentation, debug API interfaces, and sometimes Mock data. Although Postman is very useful as an interface debugging tool, it is not suitable for tasks such as maintaining API documentation. Today I would like to recommend a more powerful tool, Apifox, which is enough to meet our various needs for API, and I hope it will be helpful to everyone!

SpringBoot actual combat e-commerce project mall (50k+star) address: https://github.com/macrozheng/mall

Introduction to Apifox

Apifox is positioned as Postman + Swagger + Mock + JMeter , with functions such as API document management, API debugging, API Mock, and API automated testing. You can use one tool to solve the data synchronization problem that used multiple tools before. Efficient, timely and accurate!

Install

  • The official provided the sample project very intimately, and you can directly open it to experience the functions of Apifox. The interface is still very beautiful;

  • If we use it ourselves, we first need to create a new team at facilitate the collaborative work between team members;

  • Then create a new project in the team at . After the new build is successful, we can start to use the powerful functions of Apifox!

API document import

Apifox's API document import function is very powerful, supporting the import of up to 20 tools including Swagger, Postman, YApi, ShowDoc, etc. Next, we will experience its import function mall-tiny-swagger
  • First of all, we select the new interface button, and select import;

  • Then open the import interface, select Swagger->URL import, and enter the data URL of Swagger;

  • When importing, it will display the import preview, showing the interface and data model to be imported. Apifox will convert the entity class returned by our interface into a data model for reuse;

  • After the import is successful, the interface effect is as follows. Apifox distinguishes between viewing documents and modifying documents, which is convenient for us to manage interface documents.

Interface management

Although the interface documentation imported from Swagger is very detailed, in order to experience the more powerful functions of Apifox, we sometimes need to edit the interface information.

Interface design

  • Take a look at Apifox's request parameter interface, very detailed!

  • Look at the Apifox return result interface, which supports folding, which is not available in many tools;

  • Look at Apifox's modify the document interface to support adding status, grouping and tags.

Interface debugging

Let's experience the debugging function of Apifox, which is more powerful than Postman!
  • When we are developing interfaces, we often need to divide different environments. Apifox gives us by default the test environment, formal environment, and Mock service. These three are basically enough;

  • Before debugging the interface, we must first set the front URL corresponding to the environment, for example, here we set the test environment;

  • In Apifox, we can use the interface use case to debug our interface, and the interface use case can save the parameters we input for later testing and use;

  • Apifox do support custom interface calls before and after the operation, for example, we can add a post-operation assertion, the returned results code equal to 200 represents a successful operation;

  • At this time, we enter the wrong password to call the next interface, and the assertion will directly prompt us that the result does not meet the expectations;

  • For some interfaces, we need to pass in the Authorization to access;

  • This access can be achieved through the environment variable. First, add the post-operation in the login interface, select extract the variable, and extract the returned token into the environment variable AUTH_TOKEN ;

  • Then modify the interface documentation, in Header settings need to pass in Authorization head;

  • Next, in the interface use case, use the Authorization header through the expression to access the interface that requires login authentication normally.

Use script

Apifox's custom pre-operation and post-operation are very powerful. It not only supports simple assertions and extraction variables, but also supports writing JS scripts.
  • For example, before we judged that the operation was successful, the assertion that code is equal to 200 can be implemented using scripts;

  • At this time, we enter the wrong password to call the next interface, and the assertion will directly prompt us that the result does not meet the expectations.

Mock data

When our back-end interface has not been developed and data is needed for front-end development, data can often be provided through Mock. Apifox's Mock data function is also very powerful.
  • Apifox claims to be able to intelligently mock in your data model. Let's take a look at its rules;

  • In fact, the default Mock rules are sometimes not perfect. For example, let’s take a look at its Mock data;

  • At this point, we can data model to make the Mock data more humane. For example, we can set various states to enumerated types;

  • You can also set the logo field to the picture type @image

  • After resetting it, it is more user-friendly;

  • Then just change the environment to Mock service to call the interface of Mock data!

Test management

Apifox not only supports interface debugging, but also supports the creation of test cases for batch testing and performance testing.
  • First, we can create test cases test management;

  • Then select import from the interface use case, and select the interface use case that needs to be imported;

  • After selecting the operating environment, click Run for batch testing;

  • After the test is completed, the test report can be displayed;

  • If you want to perform a performance test, select the number of threads in the test interface;

  • After the test is completed, you can export the report to view more detailed report information.

Theme setting

Personally habits dark theme, Apifox also can choose bright primary colors and themes directly in the settings can be switched.

Summarize

Apifox is indeed a beautiful and powerful API interface tool. Postman has some interface debugging functions, and it also integrates interface document management, data mock, automated testing and other functions. It is strongly recommended that you try it!

Reference

Official document: https://www.apifox.cn/help/

Project source code address

https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-swagger

This article GitHub https://github.com/macrozheng/mall-learning has been included, welcome to Star!

macrozheng
1.1k 声望1.3k 粉丝