当前位置:网站首页>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 |
边栏推荐
- Openeuler embedded sig | distributed soft bus
- Make trouble fishing day by day
- OA项目之会议通知(查询&是否参会&反馈详情)
- kali里的powersploit、evasion、weevely等工具的杂项记录
- 行内元素和块级元素有什么区别?语义化作用
- How many tips do you know about using mock technology to help improve test efficiency?
- 熊市下 DeFi 的未来趋势
- JVM 内存布局详解(荣耀典藏版)
- 39. Combined sum
- 中文招聘文档中专业技能词抽取的跨域迁移学习
猜你喜欢

入行4年,跳槽2次,我摸透了软件测试这一行~

Research on the recognition method of move function information of scientific paper abstract based on paragraph Bert CRF

日志瘦身神操作:从5G优化到1G到底是怎么做到的!(荣耀典藏版)

Oracle, SQL Foundation

Detailed explanation of JVM memory layout (glory collection version)

For the first time, Chinese scientists used DNA to construct convolutional artificial neural network, which can complete 32 types of molecular pattern recognition tasks, or be used for biomarker signa

LT7911D Type-C/DP转mipi 方案成熟可提供技术支持

基于Xception-TD的中华传统刺绣分类模型构建

基于Paragraph-BERT-CRF的科技论文摘要语步功能信息识别方法研究

Log slimming operation: how to optimize from 5g to 1g! (glory Collection Edition)
随机推荐
使用Mock技术帮助提升测试效率的小tips,你知道几个?
Nano gold coupled antibody / protein Kit (20nm, 1mg/100 μ g/500 μ G coupling amount) preparation
中国科学家首次用DNA构造卷积人工神经网络,可完成32类分子模式识别任务,或用于生物标志物信号分析和诊断
Cy3/cy5/cy5.5/cy7 fluorescent labeling antibody / protein Kit (10~100mg labeling amount)
Miscellaneous records of powersploit, evaluation, weevery and other tools in Kali
Technology selection rust post analysis
Openeuler embedded sig | distributed soft bus
中文招聘文档中专业技能词抽取的跨域迁移学习
The University was abandoned for three years, the senior taught himself for seven months, and found a 12K job
Knowledge description framework of foreign patent documents based on knowledge elements
How to design workflow engine gracefully (glory Collection Edition)
ESP8266-Arduino编程实例-SPIFFS及数据上传(Arduino IDE和PlatformIO IDE)
39. 组合总和
数据插值——对不同量级的数据进行归一化
How does MySQL archive data?
HCIA comprehensive experiment (take Huawei ENSP as an example)
Byte side: can TCP and UDP use the same port?
System Analyst
Leetcode · 581. shortest unordered continuous subarray · double pointer
It is said that Microsoft has obtained the supply license for Xianghua! Will Huawei usher in the full lifting of the ban?