当前位置:网站首页>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
边栏推荐
- Rainbow Brackets 插件的快捷键
- 后渗透之文件系统+上传下载文件
- Mo Tianlun salon | Tsinghua qiaojialin: Apache iotdb, originated from Tsinghua, is building an open source ecological road
- [sword finger offer] 52 The first common node of two linked lists
- [BJDCTF2020]The mystery of ip|[CISCN2019 华东南赛区]Web11|SSTI注入
- 又一篇CVPR 2022论文被指抄袭,平安保险研究者控诉IBM苏黎世团队
- 每日面试1题-如何防止CDN防护被绕过
- [bjdctf2020]the mystery of ip|[ciscn2019 southeast China division]web11|ssti injection
- What did Tongji and Ali study in the CVPR 2022 best student thesis award? This is an interpretation of yizuo
- 基于eNSP的校园网设计的仿真模拟
猜你喜欢

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

Vue3 reactive database

Oneortwo bugs in "software testing" are small things, but security vulnerabilities are big things. We must pay attention to them

又一篇CVPR 2022论文被指抄袭,平安保险研究者控诉IBM苏黎世团队

Research on the principle of Tencent persistence framework mmkv

MySQL advanced - basic index and seven joins

Word中添加代码块(转载)

助力极致体验,火山引擎边缘计算最佳实践

先写API文档还是先写代码?

Redis (VII) - sentry
随机推荐
Grep output with multiple colors- Grep output with multiple Colors?
What will be the game changes brought about by the meta universe?
Apache parsing vulnerability (cve-2017-15715)_ Vulnerability recurrence
5g has been in business for three years. Where will innovation go in the future?
元宇宙带来的游戏变革会是怎样的?
每日面试1题-蓝队基础面试题-应急响应(1)应急响应基本思路流程+Windows入侵排查思路
NFT挖矿游GameFi链游系统开发搭建
Redis (IX) - enterprise level solution (II)
Animesr: learnable degradation operator and new real world animation VSR dataset
【义修换届大礼包】
Solve the problem of unable to connect to command metric stream and related problems in the hystrix dashboard
LRN local response normalization
Importing alicloud ECS locally to solve deployment problems
Hcip (Huawei Senior Network Security Engineer) (Experiment 8) (MPLS basic experiment)
港科大&MSRA新研究:关于图像到图像转换,Finetuning is all you need
The company was jailed for nonstandard bug during the test ~ [cartoon version]
Apache 解析漏洞(CVE-2017-15715)_漏洞复现
Partition marble (multiple knapsack + binary optimization)
TFTP download kernel, NFS mount file system
Thinking on large file processing (upload, download)