当前位置:网站首页>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 |
边栏推荐
- KubeVela 1.4.x 官方文档
- 行内元素和块级元素有什么区别?语义化作用
- KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书
- Object.prototype.toString.call()的原理
- 中文招聘文档中专业技能词抽取的跨域迁移学习
- 顺序表的实现
- Layout the 6G track in advance! Ziguang zhanrui released the white paper "6G unbounded AI"
- LT7911D Type-C/DP转mipi 方案成熟可提供技术支持
- Chinese patent keyword extraction based on LSTM and logistic regression
- Divide and conquer, upload large files in pieces
猜你喜欢

kali里的powersploit、evasion、weevely等工具的杂项记录

Matlab|基础知识总结一
![[极客大挑战 2019]Secret File&文件包含常用伪协议以及姿势](/img/aa/a169cdd8cc6cdfda6d2777511b4dd2.png)
[极客大挑战 2019]Secret File&文件包含常用伪协议以及姿势

40. 组合总和 II

No swagger, what do I use?

Research on intangible cultural heritage image classification based on multimodal fusion

Official document of kubevela 1.4.x

株洲市九方中学开展防溺水、消防安全教育培训活动

Oracle database objects

中国科学家首次用DNA构造卷积人工神经网络,可完成32类分子模式识别任务,或用于生物标志物信号分析和诊断
随机推荐
Vimtutor编辑
Implementation of sequence table
标准C语言学习总结10
中国农业工程学会农业水土工程专业委员会-第十二届-笔记
融合LSTM与逻辑回归的中文专利关键词抽取
Two global variables__ Dirname and__ Further introduction to common functions of filename and FS modules
Edited by vimtutor
怎样巧用断言+异常处理类,使代码更简洁!(荣耀典藏版)
开放式耳机哪个音质好、公认音质好的气传导耳机推荐
纳米金偶联抗体/蛋白试剂盒(20nm,1mg/100μg/500 μg偶联量)的制备
System Analyst
KubeVela 1.4.x 官方文档
为什么 0.1 + 0.2 不等于0.3?如何解决这个问题?
ESP8266-Arduino编程实例-定时器与中断
中国科学家首次用DNA构造卷积人工神经网络,可完成32类分子模式识别任务,或用于生物标志物信号分析和诊断
display 各值的区别
比UUID更快更安全NanoID到底是怎么实现的?(荣耀典藏版)
开放式耳机哪个品牌好、性价比最高的开放式耳机排名
Research on weapon equipment attribute extraction based on attribute word completion
Matlab|基础知识总结一