As a back-end developer, we often need to maintain API documentation, debug API interfaces, and sometimes Mock data. Postman, while great as an interface debugging tool, is not very good for jobs like maintaining API documentation. Today I recommend a more powerful tool Apifox, enough to meet our various needs for API, hope to help you!

SpringBoot e-commerce project mall (50K + STAR) address: github.com/macrozheng/…

Apifox profile

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

The installation

  • Apifox is easy to install. You can download the installation package and decompress it directly from www.apifox.cn/

  • The authorities were kind enough to provide itThe sample project, directly open to experience the function of Apifox, look at the interface is very beautiful;

  • We need it first if we use it ourselvesThe new teamTo facilitate collaborative work among team members;

  • And then in the teamNew project, we can start to use the power of Apifox!

API Document import

Apifox API document import is very powerful, including Swagger, Postman, YApi, ShowDoc and more than 20 tools to import. Let’s use the interface from the previous mall tiny-Swagger project to experience its import functionality!

  • First we chooseThe new interfaceButton, selectThe import;

  • Then open the import screen and selectSwagger URL - > import, enter Swagger’s data URL;

  • Displays when importingImport the previewTo display the ones to importinterfaceandThe data modelApifox 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, facilitating the management of interface documents.

Interface management

Although the interface documentation imported from Swagger is quite detailed, we sometimes need to edit the interface information in order to experience Apifox’s more powerful capabilities.

Interface design

  • Take a look at the Apifox request parameters screen, very detailed!

  • Take a look at the Apifox return result screen, which supports folding, which many tools do not have;

  • Take a look at ApifoxModify the documentInterface to add status, groups, and labels.

Interface debugging

Let’s take a look at the debugging capabilities of Apifox, which is even more powerful than Postman!

  • When we develop interfaces, we often need different environments, which Apifox gives us by defaultThe test environment,Formal environment,Mock servicesThese three are basically enough;

  • Before debugging the interface, we need to set up the corresponding environmentLead the URLFor example, here we setThe test environment;

  • We can use it in ApifoxThe interface use casesTo debug our interface, the interface use case can save the parameters we enter for later testing;

  • Apifox supports custom operations before and after interface calls, such as inThe rear operationAdd aassertions, returns the resultCode is equal to 200The operation succeeds.

  • When we enter the wrong password to call the interface, the assertion will directly inform us that the result does not meet the expectation.

  • There are some interfaces we need to pass inAuthorizationThe head can access;

  • This kind of access we can get throughThe environment variableTo implement, first add in the login interfaceThe rear operation, the choice ofExtract variableTo extract the returned token into an environment variableAUTH_TOKEN;

  • Then modify the interface document inHeaderThe Settings need to be passedAuthorizationHead;

  • The next inThe interface use casesIs used by an expressionAuthorizationThe header can normally access the interface that requires login authentication.

Using a script

Apifox’s custom pre – and post-operations are very powerful, supporting not only simple assertions and extraction of variables, but also JS scripting.

  • For example, before we judged the operation to be successful, assertCode is equal to 200You can do this using scripts;

  • When we enter the wrong password to call the interface, the assertion will directly tell us that the result does not match the expected result.

The Mock data

When the back-end interface is not developed and the front-end development needs data, we can often provide data through Mock. Apifox’s Mock data function is also very powerful.

  • Apifox claims to be able to name fields based on your data modelIntelligent Mock, let’s look at its rules;

  • In fact, the default Mock rule is sometimes not very good, for example, let’s take a look at its Mock data;

  • At this point we can takeThe data modelFor example, we can set various states to enumerated types.

  • You can also pass the LOGO field@imageThis method is set to image type;

  • After the reset, it is much more user-friendly;

  • All you need to do is change the environment toMock servicesYou are ready to call the Mock data interface!

Test management

Apifox not only supports interface debugging, but also supports the creation of test cases for batch testing and performance testing.

  • First of all, we canTest managementCreate test cases in;

  • Then chooseImport from the interface use case, select the interface cases to be imported;

  • Choose goodRuntime environmentClick Run for batch test;

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

  • If you want to perform a performance test, select it in the test screenThe number of threadsCan;

  • When the test is complete, you can passExport the reportFor more detailed reports.

Theme Settings

I prefer dark theme, Apifox also can choose bright theme and main color, you can switch directly in the Settings.

conclusion

Apifox is a beautiful, powerful API tool. Postman has almost all of the interface debugging functions, including interface document management, data Mock, automated testing, and so on.

The resources

Official document: www.apifox.cn/help/

Project source code address

Github.com/macrozheng/…

In this paper, making github.com/macrozheng/… Already included, welcome everyone Star!