当前位置:网站首页>Do you write API documents or code first?
Do you write API documents or code first?
2022-06-30 18:22:00 【InfoQ】
The code is not moving , Document first
1. Written document ,2. Others don't write documents The short-term benefits of writing documents are far less than the costs Long term benefits How to do ?
Short term gains The cost The original working mode of the team
- API The designerUseSwaggerWrite API file
- The front-end developmentUse mock.js mock fake API data
- The backend developmentUse Postman debugging API
- TestersUse JMeter test API
The problem we've had
- Our team enters the development at the front and back end simultaneously , You can't wait until the back-end development is completed to issue the interface document , The front end enters the development stage , So back-end code annotations are used to automatically generate Swagger Not for us .
- WriteSwaggerDocument efficiency is low , And there is a learning threshold , Let everyone in the team write skillfully Swagger Documentation is unrealistic , What's more, there are new people in the team .
- Developers inSwaggerAfter defining the document , Interface debugging also needs to go Postman Define it again .
- The front-end development Mock When it comes to data mock Define it in the tool , Set it manually Mock The rules .
- Testers need to go to JMeter Define it again .
- Front end according to mock The data from the tool has been developed , Back end according toSwaggerThe defined interface document is developed , Each test passed , I thought I could go online right away , As a result, a variety of problems were found : Interface changes in the original development process , Only modifiedSwagger, But they didn't synchronize the changes in time mock.
- Again , Test in JMeter Well written test cases , When it's really running, you'll find all kinds of inconsistencies .
- The development process , It is often found that the interface document defined at the beginning is unreasonable , Need temporary adjustment , Interface changes often occur , But the document was not updated .
- Time is long. , The inconsistencies will get more and more serious .
How to solve
Short term gains The cost - Reduce the cost of writing documents
- Increase the benefits of writing documents
- With
Full VisualizationInterface to write documents , And zero learning cost ,New peopleYou can get started .
- Data structures that can be defined through interface documents
Automatically mockData , No needThe front-end developmentTo writemockThe rules , Go straight to work .
- The backend developmentDebug the interface based on the interface document , Without going to
PostmanDebugging ; If the interface changes , When debugging, the document is automatically updated , Zero cost ensures the timeliness of interface maintenance ; Automatically check the data structure according to the document , No visual verification is required , No need to write assertions manually .
- The backend developmentEach time a function is debugged, it is saved as a
Interface use cases.
- TestersUse it directly
Interface use casesTest interface .
- TestersMore interface documents automatically generate test cases , And then like
JMeterJust test it directly on it .
- According to the data structure defined in the interface document , Automatic generation of front and rear
Data modelCode .
What do I do ? Do it yourself !
Postman + Swagger + Mock + JMeterApifoxBest practices
- front end( orBack end) stayApifoxIt's fixed
Interface documentfirst draft .
- Front and rear endsReview together 、 perfect
Interface document, reach a decisionInterface use cases.
- front endUseApifoxAutomatically generated
Mock dataEntry into development , Without handwritingmockThe rules , Go straight to work .
- Back endUse
Interface use casesDebug the interface in development , The system is defined according to the interface documentAutomatic verificationWhether the returned data is correct , As long as all interface use cases are debugged , The interface development is completed .
- Back endAfter development ,Testers( It can also beBack end) Use
Set testFunction for multi interface integration test , Completely test the whole interface call process .
- Front and rear endsAll 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 .
Apifox Solution
One 、 How to solve these problems
1、Apifox location
Apifox = Postman + Swagger + Mock + JMeter2、Apifox Purpose
3、Apifox function
- Interface design:Apifox Interface documentation followsOpenApi3.0 ( primary Swagger)、JSON SchemaAt the same time , It's very easy to use
visualizationDocument management function , Zero learning cost , Very efficient . And support online sharing of interface documents .
- Data model: Reusable data structure , Defining interfaces
Return data structureAndRequest parameter data structure( only JSON and XML Pattern ) You can directly reference . Support model direct nested reference , direct JSON/XML Smart import , Support oneOf、allOf And other advanced combination modes .
- Interface debugging:Postman Some functions , For example, environment variables 、 In front of / Post script 、Cookie/Session Global Shared And so on ,Apifox There are , And ratio Postman More efficient and easy to use . After the interface runs, click
Save as use caseButton , It can generateInterface use cases, Interface use cases can be run directly later , No more parameters need to be entered , Very convenient . Custom script 100% compatible Postman grammar , And support running javascript、java、python、php、js、BeanShell、go、shell、ruby、lua And other language codes .
- Interface use cases: Usually, an interface has multiple use cases , such as
The parameters are correctUse cases 、Parameter errorUse cases 、Data is emptyUse cases 、Different data statesUse cases, etc . The correctness of data will be automatically verified when running the interface case , Using interface use cases to debug interfaces is very efficient .
- Interface data Mock: built-inMock.jsRules engine , Very convenient mock All kinds of data , And you can define the data structure and write mock The rules . Support adding “ expect ”, According to the request parameters, different mock data . most important of all Apifox
Zero configurationthat will do Mock Very human data , The details are introduced later in this paper .
- Database operation: Support reading database data , Used as an interface request parameter . Support reading database data , Used to verify ( Assertion ) Whether the interface request is successful .
- Interface automation testing: Provide interface set testing , You can choose the interface ( Or interface use cases ) Quickly create test sets . At present, more functions of interface automation test are still under development , Coming soon ! The goal is : JMeter Some functions are basically , And use it better .
- Quick debugging: similar Postman Interface debugging mode , It is mainly used for temporary debugging
No documentation requiredThe interface of , You can quickly debug without defining the interface in advance .
- Code generation: Define according to the interface and data model , Automatic system generation
Interface request code、Front end business codeAndBack end business code.
- Teamwork:Apifox Born for teamwork , Interface cloud real-time synchronous update , ripe
The team / project / Member rightsmanagement , Meet the needs of various enterprises .
Two 、Apifox It's not just about getting through the data
1、 Interface support “ Use case management ”
The right use case Parameter error use case Data is empty use case Different data state use cases 2、“ Data model ” Definition 、 quote
3、 During debugging “ Automatic verification ” data structure

4、“ visualization ” Set assertion


5、“ visualization ” Set extraction variables

6、 Support database operations

7、“ Zero configuration ”Mock Very human data
Zero configuration 
Zero configuration high efficiency Zero configuration - Apifox According to the data structure in the interface definition 、 data type , Automatic generation mock The rules .
- Apifox Built in intelligence mock Rule base , According to the field name 、 Field data type , Intelligent optimization automatically generated mock The rules . Such as : The name contains the string
imageOfstringThe type field , Automatically mock Give a picture address URL; Include stringtimeOfstringThe type field , Automatically mock Give a time string ; Include stringcityOfstringThe type field , Automatically mock Name a city .
- Apifox According to the built-in rules , Can automatically identify pictures 、 Head portrait 、 user name 、 cell-phone number 、 website 、 date 、 Time 、 Time stamp 、 mailbox 、 Province 、 City 、 Address 、IP Etc , thus Mock Very human data .
- In addition to the built-in mock The rules , Users can also customize the rule base , Meet a variety of personalized needs . Support use
Regular expressions、wildcardTo match field name customization mock The rules .
8、 Generate online interface documentation

9、 Code auto generation
Custom code template 10、 Import 、 export
- Support export
OpenApi (Swagger)、Markdown、HtmlAnd so on , Because you can exportOpenApiFormat data , So you can use OpenApi (Swagger) Rich ecological tools to complete a variety of interface related things .
- Support import
OpenApi (Swagger)、Postman、HAR、RAML、RAP2、YApi、Eolinker、NEI、DOClever、ApiPost、Apizza、ShowDoc、API Blueprint、I/O Docs、WADL、Google DiscoveryAnd so on , Facilitate the migration of old projects .
3、 ... and 、 Follow up function planning
- Release Apifox WEB edition , Support the use of... On the browser side Apifox.
- Interface performance test support ( similar JMeter).
- Support plug-in market , You can develop your own plug-ins .
- to open up Apifox API, Allow developers to pass through API call Apifox The function of .
- Support more interface protocols , Such as
GraphQL、gRPC、websocketetc. .
- Support offline use , Project can choose online synchronization ( Teamwork ) Or just local storage ( Stand alone offline use ).
Four 、 more Apifox Function screenshot








5、 ... and 、 Apifox Download address
边栏推荐
- [software testing] basic knowledge of software testing you need to know
- Radio and television 5g officially set sail, attracting attention on how to apply the golden band
- leetcode:787. The cheapest transfer flight in station K [k-step shortest path + DFS memory + defaultdict (dict)]
- [binary tree] preorder traversal to construct binary search tree
- Servlet operation principle_ API details_ Advanced path of request response construction (servlet_2)
- Ardunio esp32 DH11 real time uploading temperature and humidity Alibaba cloud self built mqtt
- Flutter custom component
- Three methods of modifying time zone in MySQL
- Deep understanding of JVM (I) - memory structure (I)
- 基于SSH的客户关系CRM管理系统
猜你喜欢

Switching routing (VLAN) experiment

每日面试1题-蓝队基础面试题-应急响应(1)应急响应基本思路流程+Windows入侵排查思路

DeFi借贷协议机制对比:Euler、Compound、Aave和Rari Capital

漏洞复现----38、ThinkPHP5 5.0.23 远程代码执行漏洞

Deep understanding of JVM (I) - memory structure (I)

Solve the problem of unable to connect to command metric stream and related problems in the hystrix dashboard

Deep understanding of JVM (II) - memory structure (II)

漏洞复现----35、uWSGI PHP 目录遍历漏洞 (CVE-2018-7490)

ABAP-发布Restful服务

Simulation of campus network design based on ENSP
随机推荐
Daily interview 1 question - basic interview question of blue team - emergency response (1) basic idea process of emergency response +windows intrusion screening idea
MySQL advanced - Architecture
MySQL reports that the column timestamp field cannot be null
Deep understanding of JVM (III) - memory structure (III)
Design and principle of tubes responsive data system
[Netease Yunxin] playback demo build: unable to convert parameter 1 from "asyncmodalrunner *" to "std:: nullptr\u T"**
Flutter custom component
每日面试1题-如何防止CDN防护被绕过
腾讯云安装mysql数据库
ASP. Net generate verification code
Tencent cloud installs MySQL database
Solve the problem of unable to connect to command metric stream and related problems in the hystrix dashboard
Deep understanding of JVM (IV) - garbage collection (I)
Unity实战之一个脚本实现雷达图
Synchronized summary
Shortcut keys for the rainbow brackets plug-in
DeFi借贷协议机制对比:Euler、Compound、Aave和Rari Capital
IEEE TBD SCI impact factor increased to 4.271, ranking Q1!
[sword finger offer] 53 - I. find the number I in the sorted array
后渗透之文件系统+上传下载文件