当前位置:网站首页>Apifox: satisfy all your fantasies about API
Apifox: satisfy all your fantasies about API
2022-07-28 22:00:00 【Don't eat tomatoes】

List of articles
️ One 、Api What are the difficulties of management ?
Believe that whether it is the front end , Or back-end testers and developers , Have encountered such difficulties . Data consistency between different tools is very difficult 、 Inefficient . Data inconsistency between multiple systems , Leading to inefficient collaboration 、 Frequent problems , Developers and testers are in agony .
- Developers in Swagger After defining the document , Interface debugging also needs to go Postman Define it again .
- The front-end development Mock When it comes to data mockjs Define it again , You also need to set it manually Mock The rules .
- Testers need to go to JMeter Define it again .
- Front end according to mockjs Mock The data is developed , Back end according to Swagger The defined interface document is developed , They all passed the test , I thought I could go online right away , As a result, a variety of problems were found :
- The interface changed during development , Only modified Swagger, But they didn't synchronize the changes in time mockjs.
- The interface data type of back-end development is inconsistent with the document , It's hard to see the problem with the naked eye .
- Again , Test in JMeter Well written test cases , When it's really running, you'll find all kinds of inconsistencies .
- Time is long. , The inconsistencies will get more and more serious .
Two 、Apifox What is it? ?
Apifox yes API file 、API debugging 、API Mock、API Automated testing integrated collaboration platform , location Postman + Swagger + Mock + JMeter.
Through a system 、 A piece of data , Solve the problem of data synchronization between multiple systems . Just define API file ,API debugging 、API data Mock、API Automated testing can be used directly , There is no need to redefine ;API Documentation and API Development and debugging use the same tool ,API After the commissioning, it can be guaranteed and API The document definition is exactly the same . Efficient 、 In time 、 accuracy !
Next , I will demonstrate and introduce one by one from the following aspects :
- API Document design
- API debugging
- API automated testing
- API data Mock
- CI Continuous integration
- Database operation
- Automatic code generation
- Support HTTP、TCP、RPC
- Data import / export
- Teamwork
3、 ... and 、 Interface design ( Interface document )
️ 3.1 Interface document
Interface design defines the interface document specification ( Such as interface path 、 Parameters 、 Return value 、 Data structure, etc ).
and Postman Dissimilarity ,[Apifox] It's a distinction
Interface designandInterface operationOf two concepts .
- Interface design : namely New interface Interface or interface details edit Interface , The purpose is Define the interface document specification , instead of function Interface , Therefore, the interface can only define basic interface information 、
Parameter nameAnd parameter description , Instead of settingParameter values. Parameter values 、 Pre script / Post script Please wait for information atInterface operationInterface orInterface use casesInterface filling . - Interface operation : That is... In the interface details function Interface , The purpose is Temporary commissioning interface , function After finishing , Need to click
Save as use case, To fill in Parameter values 、 Pre script / Post script When the information is saved ; Otherwise closed tab after , This information will be lost .
3.2 Quick start
Click... Next to the search box on the left
+Click button No. to open the new window , You can also use Shortcut key Ctrl(⌘) + N.
In the open window , Directly define interface related information .

3.3 Interface path
With a slash / Starting interface path part , Such as /pets、/pets/{id}.
Interface path Suggest
Do not include HTTP Agreement and domain name, This part of the proposal Environmental management OfIn front of URLSet in the , Interface debugging URL Will automatically add the current environmentIn front of URL.In special cases, it is necessary to bring... On the interface path
HTTP Agreement and domain nameOf , The system can also support , But it's not recommended . Interface debugging , If the system detects that the interface path ishttp://orhttps://Initial , Will automatically ignore the current environment URL.Apifox Medium
Path ParametersIs wrapped in braces to indicate , Instead of starting with a colon . The correct sample :/pets/{id}, The wrong sample/pets/:id.Interface path Cannot contain
Query Parameters( namely URL in?Later parameters ),Query The parameters are at the bottomRequest parametersFill in part of .
Four 、 Team management
Member permissions are divided into two parts : Team permissions and member permissions . Team permissions refer to the permissions of members for team operations , Project permission refers to the permission of members to operate the project .
4.1 Rights management
Team role score owner 、 Managers and ordinary users , The corresponding permissions are as follows :
| Permission to name | owner | Administrators | Ordinary members |
|---|---|---|---|
| Modify team data | √ | × | × |
| Hand over the team | √ | × | × |
| Disband the team | √ | × | × |
| View member permission list | √ | √ | × |
| Modify member permissions | √ | √ | × |
| The invitation / Remove members | √ | √ | × |
4.2 Project permissions
In order to meet the multi-level management needs of the team , Each member can set up administrators by project 、 Ordinary members 、 Read only members 、 Forbidden roles , The corresponding permissions are as follows :
| Permission to name | Administrators | Ordinary members | Read only members | Blocking access |
|---|---|---|---|---|
| Project addition, deletion and modification | √ | × | × | × |
| Project information modification | √ | × | × | × |
| Provider documentation | √ | √ | √ | × |
| Interface addition, deletion and modification | √ | √ | × | × |
| Interface view debug | √ | √ | √ | × |
| Use case addition, deletion and modification | √ | √ | × | × |
| Use case viewing and running | √ | √ | √ | × |
| Addition, deletion and modification of test suite | √ | √ | × | × |
| The test suite runs | √ | √ | √ | × |
| Data model addition, deletion and modification | √ | √ | × | × |
| Data model view | √ | √ | √ | × |
| Environment addition, deletion and modification | √ | √ | × | × |
| Mock Addition, deletion and modification of rules | √ | √ | × | × |
| public Response Additions and deletions | √ | √ | × | × |
| Public script addition, deletion and modification | √ | √ | × | × |
| Database connection addition, deletion and modification | √ | √ | × | × |
| Add, delete and modify user-defined functions | √ | √ | × | × |
| Addition, deletion and modification of variables | √ | √ | × | × |
| Variable local value setting | √ | √ | √ | × |
| Import export data | √ | × | × | × |
4.3 Instructions
When you need to modify permissions or view member permissions , You can click on... In the upper left corner Project name , Go to the team page . Click... Under the corresponding item member / jurisdiction tab, Click the corresponding member Set up , You can see the team permissions and project permissions of the member in the project , And make changes as needed .
️ 5、 ... and 、 Teamwork process
- front end ( or Back end ) stay [Apifox] It's fixed
Interface documentfirst draft . - Front and rear ends Review together 、 perfect
Interface document, reach a decisionInterface use cases. - front end Use the interface automatically generated by the system according to the interface document
Mock dataEntry into development , No handwriting required mock The rules . - Back end Use
Interface use casesDebug the interface in development , As long as all interface use cases are debugged , The interface development is completed . If the interface changes during development , When debugging, the document is automatically updated , Zero cost ensures the timeliness of interface maintenance . - Back end Each time a function is debugged, it is saved as a
Interface use cases. - Testers Use it directly
Interface use casesTest interface . - After all interfaces are developed , Testers ( It can also be Back end ) Use
Set testFunction for multi interface integration test , Completely test the whole interface call process . - Front and rear ends All developed , Front end from
Mock dataSwitch toOfficial data, Joint commissioning usually goes very smoothly , Because both the front and back sides fully comply with the specification of the interface definition .
6、 ... and 、 Import data
6.1 Functional specifications
Support import OpenApi ( primary Swagger)、Postman、HAR、RAML、RAP2、JMeter、YApi、Eolinker、NEI、DOClever、ApiPost 、Apizza 、DOCWAY、ShowDoc、apiDoc、I/O Docs、WADL、Google Discovery And so on , Facilitate the migration of old projects .
6.2 Manual import
open Project settings panel , Click on Manual import , You can choose file import or URL Import .

To import Apifox Format as an example , Import options include : Interface 、 Data model 、 Environmental Science 、 The test case 、 test suite
7、 ... and 、 Derived data
7.1 Functional specifications
Support direct export
OpenAPI ( primary Swagger)、HTML、Markdown、ApifoxAnd so on .OpenAPI (Swagger)Support export3.1、3.0、2.0edition .OpenAPI (Swagger)Support exporting offline files , Or open it directly URL.

7.1 export PDF、Word Method
Currently, direct export is not supported PDF、Word And other format data , However, external tools can be used to Markdown Convert to the corresponding format .
If you use [Typora] Can be Markdown Export to PDF、Word 、OpenOffice、Epub Equiform .
8、 ... and 、Mock grammar
Apifox Mock Syntax is fully compatible Mock.js ( Data placeholder mode ), And extends some Mock.js No grammar ( Such as domestic mobile phone number @phone).
If existing Mock Grammar cannot meet the demand , It is recommended to use Regular expressions @regexp To achieve flexible customization . Regular expressions can basically meet the needs of various special scenarios .
8.1 The basic way of writing
| How to write it | explain |
|---|---|
With @ The starting string | call Mock Syntax rules generate corresponding data . |
| For example, the generated data type is inconsistent with the defined data type , Will automatically convert . | |
Not @ The starting string | The data type is string when , Original output . |
| Other data types , The string will be automatically converted to the corresponding data type . | |
| Special characters :null | The data type is allowed to be null when , Output null. |
Otherwise, automatic conversion , If the data type is string, Output "null". | |
| Special characters :true | The data type is boolean when , Output true. |
Otherwise, automatic conversion , If the data type is string, Output "true". | |
| Special characters :false | The data type is boolean when , Output false. |
Otherwise, automatic conversion , If the data type is string, Output "false". |
Automatic conversion It's using javascript The language is converted by default data conversion method .
8.2 Regular expressions
| The rules | Example | Sample results |
|---|---|---|
| @regexp( regexp ) | @regexp(/\d+/) | “36436” |
| @regexp(/\d{3,5}/) | “343” | |
| @regexp(/^[a-zA-Z][A-Za-z0-9_-.][email protected]$/) | “[email protected]” |
Be careful :
- Apifox Version number is greater than or equal to
1.0.12To support regular expressions . - regexp The parameter must be
/Start and end .
Nine 、 Script
[Apifox] Contains a program based on Javascript Script engine for , Through script (JavaScript code snippet ) You can add dynamic behavior when interface requests or collection tests are implemented .
9.1 What the script can do
- test ( Assertion ) The correctness of the result returned by the request ( Post script ).
- Dynamically modify interface request parameters , Such as adding interface signature parameters ( Pre script ).
- Transfer data between interface requests ( Use scripts to manipulate variables ).
- Scripts can be direct Call programs written in other languages , Support
java(.jar)、python、php、js、BeanShell、go、shell、ruby、LuaAnd other languages . - other .
️ 9.2 Usage mode
You can add scripts in the following two steps :
- Before sending the request to the server , Use Pre script .
- After receiving the response , Use Post script ( Assertion testing ).

9.3 Global scripts and group scripts
Support
overall situationSet up ( stayProject OverviewSet in the ) Front operation 、 The rear operation , After setting, all interfaces in the project will take effect at runtime .Support
groupingSet the pre operation in 、 The rear operation , After setting, all interfaces in the group will take effect at runtime .
The execution process of interface request is as follows :
[ Global pre script ] -> [ Group pre script ] -> [ Interface pre script ] -> [ Send interface request ] -> [ Return interface result ] -> [ Global post script ] -> [ Group post script ] -> [ Interface post script ]
9.4 Debug script
The debugging script can be in Pre script and Post script Written in , Use console.log('hello') Mode to write debugging information to the console , open Console You can view it .
Ten 、 Shortcut key
In order to improve your development efficiency , You can also use various shortcut keys :
| function | Windows / Linux | macOS |
|---|---|---|
| New interface | Ctrl + N | ⌘ + N |
| New quick debugging | Ctrl + T | ⌘ + T |
| Save interface / Save the use cases | Ctrl + S | ⌘ + S |
| Send a request | Ctrl + Enter | ⌘ + Enter |
| Switch to 【 function 】Tab | Ctrl + Enter | ⌘ + Enter |
| close Tab | Ctrl + W | ⌘ + W |
| closed Tab | Ctrl + Alt + W | ⌘ + Option + W |
| Switch to next Tab | Ctrl + Tab or Ctrl + PageDown | ⌘ + Option + Right arrow key or ⌘ + Shift + ] |
| Switch to the previous Tab | Ctrl + Shift + Tab or Ctrl + PageUp | ⌘ + Option + left arrow or ⌘ + Shift + [ |
| Jump to a specific tab | Ctrl + 1 To Ctrl + 8 | ⌘ + 1 To ⌘ + 8 |
| Go to the last tab | Ctrl + 9 | ⌘ + 9 |
| Import data | Ctrl + O | ⌘ + O |
| Import packet capture data (cURL) | Ctrl + I | ⌘ + I |
边栏推荐
- Oracle built-in functions
- Information fusion method and application of expert opinion and trust in large group emergency decision-making based on complex network
- 90. 子集 II
- RHCSA第一天
- 系统分析师
- Meeting notice of OA project (Query & whether to attend the meeting & feedback details)
- 39. 组合总和
- Apple M1 processor details: performance and energy efficiency have doubled, and Intel Core i9 is no match!
- Soft test --- database (3) data operation
- KubeVela 1.4.x 官方文档
猜你喜欢

如何优雅的设计工作流引擎(荣耀典藏版)

Zhuzhou Jiufang middle school carried out drowning prevention and fire safety education and training activities
![Introduction to C language [detailed]](/img/ac/9ba2e298faabd8dc4c76575ea182d1.png)
Introduction to C language [detailed]

MATLAB从入门到精通 第1章 MATLAB入门

Implementation of sequence table

fluke dtx-1800测试精度有必要进行原厂校准吗?

Research on weapon equipment attribute extraction based on attribute word completion

Professional Committee of agricultural water and soil engineering of China Association of Agricultural Engineering - 12th session - Notes

如何高效、精准地进行图片搜索?看看轻量化视觉预训练模型

Msfvenom makes master and controlled terminals
随机推荐
Oracle triggers
如何在 Web3中建立一个去中心化社区
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
Object based real-time spatial audio rendering - Dev for dev column
中文招聘文档中专业技能词抽取的跨域迁移学习
[Bluetooth Bluetooth development] VIII. Transmission layer of ble protocol
Pytoch learning record (III): random gradient descent, neural network and full connection
The Swedish court lifted the 5g spectrum auction ban on Huawei and ZTE
Huawei releases the first electric drive system driveone: charging for 10 minutes, endurance of 200km
Esp8266 Arduino programming example - deep sleep and wake up
Matlab | basic knowledge summary I
display 各值的区别
04.toRef 默认值
Is it necessary to calibrate the fluke dtx-1800 test accuracy?
Openeuler embedded sig | distributed soft bus
Nano gold coupled antibody / protein Kit (20nm, 1mg/100 μ g/500 μ G coupling amount) preparation
Hold high the two flags of 5g and AI: Ziguang zhanrui Market Summit is popular in Shencheng
JVM 内存布局详解(荣耀典藏版)
How is nanoid faster and more secure than UUID implemented? (glory Collection Edition)
Coolpad voluntarily terminated the patent infringement lawsuit against Xiaomi