Two things programmers hate most: 1. Write documentation, and 2. Other people don’t write documentation. The reason most developers don’t want to document apis: The short-term benefits of documenting far outweigh the costs, but not everyone can stick with something that has long-term benefits. If you delay your current project by writing a document, your boss will come after you directly. But the long-term benefits of not writing documentation are low and invisible to the boss. That’s the reality. It’s very difficult to get people to do things against humanity.
As a front – and back-end development team, we often see a scene where the front – and back-end developers get together and have a heated discussion about “What’s wrong with your interface?” “, “Why is the interface broken again?” “, “Wait a minute, LET me debug it”, “Try again…” .
Can we write the interface documentation, and we all develop according to the documentation? It’s hard because it’s cumbersome to write and maintain documentation, and it’s time consuming, and there are often apis that are updated, but the documentation is still old, and all kinds of synchronization is inconsistent, which delays each other.
Our team also encountered the same problem before. As the head of the R&D team, how did I lead the team to solve this problem?
How to do?
The solution is simple: if you can make the short-term benefits of writing/maintaining documentation far outweigh the costs, all problems will be solved and developers will be more than happy to write interface documentation.
How the team used to work
- Write interface documents with Swagger
- The front-end development uses RAP Mock interface data
- Back-end development uses the Postman debugging interface
- Testers use JMeter to test the interface
The problems we have
- Our team entered the development synchronously at the front and back ends, and could not wait for the end to finish the development of the interface document, and then enter the development at the front end. Therefore, it is not suitable for us to automatically generate Swagger by using back-end code comments.
- It is very inefficient to write Swagger documents, and there is a learning threshold. It is unrealistic for all members of the team to write Swagger documents proficiently, let alone there are constantly new members in the team.
- After Swagger has defined the document, developers need to go to Postman to define it again during interface debugging.
- The front-end Mock data development needs to RAP again to define Mock rules manually.
- Testers need to go to JMeter to define it.
- The front-end was developed according to the data derived from RAP Mock, and the back-end was developed according to the interface document defined by Swagger. They passed their respective tests and thought they could be launched immediately. However, various problems were found in the first connection: in the original development process, the interface was changed and only Swagger was modified, but RAP was not timely synchronized.
- Similarly, the tests found various inconsistencies when JMeter’s written test cases were actually run.
- During the development process, it is often found that the interface document defined at the beginning has some unreasonable places and needs to be adjusted temporarily. It is often found that the interface is changed, but the document is not updated.
- Over time, the inconsistencies get worse and worse.
How to solve
The short-term benefits of writing and maintaining documentation far outweigh the costs in one of two ways:
- Reduce the cost of writing documentation
- Increase the revenue after writing the document
With that in mind, wouldn’t it be cool to have a tool that did the following?
- In order to
Complete visualization
Interface to document, and zero learning cost,The coupleIt’s easy to get started. - Data structures that can be defined through interface documentation
Automatic mock
Output data without having toThe front-end developmentTo writemock
The rules. - The backend developmentDebug the interface based on the interface documentation without having to go to
Postman
The debugging; If the interface is changed, the document will be automatically updated during debugging, which ensures the timeliness of interface maintenance at zero cost. - The backend developmentSave one function after each debugging
The interface use cases
. - The testerDirect use of
The interface use cases
Test the interface. - The testerMore interface documentation automatically generates test cases, then like
JMeter
As well as testing directly on top. - The front and back ends are automatically generated based on the data structure defined by the interface document
The data model
The code.
All we need is a tool that:
It solves the data synchronization problem among multiple systems by using one set of systems and one piece of data. Once the interface documentation is defined, interface debugging, data Mock, and interface testing can be used directly without needing to be defined again. The interface documentation and interface development and debugging use the same tool, after the interface debugging can ensure that the definition of the interface documentation is completely consistent. Efficient, timely and accurate!
To do this, we tried almost every tool on the market, but unfortunately, we couldn’t find the right one.
How to do? Do yourself!
So, we implemented a Postman + Swagger + RAP + JMeter by ourselves
The tool was Apifox, and over a long period of iteration and iteration, we basically implemented the original vision, solved almost all of our initial problems perfectly, and became very popular within the company. And develop our own best practices.
Best practices
- The front end(orThe back-end) inApifoxOn the set
Interface documentation
The first draft. - Before and after the end of theReview and improve together
Interface documentation
Good,The interface use cases
. - The front endUsing the system according to the interface document automatically generated
The Mock data
Enter development. - The back-enduse
The interface use cases
Debugging and development of the interface, the system according to the definition of the interface documentAutomatic calibration
Whether the returned data is correct, as long as all interface use cases debugging through, the interface development is completed. - The back-endWhen the development is complete,The tester(It could also beThe back-end) to use
A collection of test
Function for multi-interface integration test, complete test the whole interface call process. - Before and after the end of theAll developed, the front end from
The Mock data
Switch to theOfficial data
, syndication usually goes smoothly because both the front and back ends fully comply with the specification of the interface definition.
Foreign service
That’s right, now that we’ve productized Apifox to external services, your team can use Apifox directly.
Website: www.apifox.cn
Apifox solution
First, how to solve these problems
1. Apifox positioning
Apifox = Postman + Swagger + Mock + JMeter
It solves the data synchronization problem among multiple systems by using one set of systems and one piece of data. Once the interface documentation is defined, interface debugging, data Mock, and interface testing can be used directly without needing to be defined again. The interface documentation and interface development and debugging use the same tool, after the interface debugging can ensure that the definition of the interface documentation is completely consistent. Efficient, timely and accurate!
2. Purpose of Apifox
Save every minute of r&d team!
3. Apifox function
- Interface design: Apifox Interface documentOpenApi3.0 (formerly Swagger),JSON SchemaSpecification at the same time, provides a very useful
visualization
Document management function, zero learning cost, very efficient. It also supports online sharing of interface documents. - The data model: reusable data structures that define interfaces
Return data structure
andRequest parameter data structure
(only JSON and XML schemas) can be referenced directly. Support model directly nested reference, direct JSON/XML intelligent import, support advanced combination modes such as oneOf and allOf. - Interface debuggingApifox has all of Postman’s features, such as environment variables, pre/post scripts, Cookie/Session global sharing, and is much more efficient than Postman. Click after the interface runs
Save as a use case
Button, can be generatedThe interface use cases
, you can directly run the interface case without input parameters, which is very convenient. Custom scripts are 100% compatible with Postman syntax and can run javascript, Java, Python, PHP, JS, BeanShell, Go, shell, Ruby, Lua and other languages. - The interface use cases: Usually an interface will have multiple case use cases, such as
Parameters correctly
Use cases,Parameter error
Use cases,Data is empty
Use cases,Different data states
Use cases and so on. It is very efficient to debug the interface with the interface use case. - Interface data Mock: built-inMock.jsRules engine, which makes it easy to mock out data and write mock rules while defining data structures. Support for adding “expectations” that return different mock data based on request parameters. The most important is Apifox
Zero configuration
You can Mock out very human data, as described later in this article. - Database operation: Reads database data as interface request parameters. Support for reading database data to verify (assert) the success of an interface request.
- Interface automation testing: Provides interface collection tests that can be quickly created by selecting an interface (or interface use case). At present, more functions of interface automation testing are still under development, please look forward to it! The goal: To have almost all of JMeter’s features and make them better.
- Quick debugging: interface debugging mode similar to Postman, mainly used for temporary debugging
No documentation required
The interface can be quickly debugged without defining the interface in advance. - Code generation: Automatically generated by the system according to the interface and data model definition
Interface request code
,Front-end business code
andBack-end business code
. - Team collaboration: Apifox is born for team collaboration, interface cloud real-time synchronization update, mature
Team/project/member permissions
Management to meet the needs of various enterprises.
Apifox does more than just get through the data
It would be a mistake to think that Apifox only does data access to improve the efficiency of the r&d team. Apifox has also made a number of innovations to improve developer productivity.
1. Interface support “Use case Management”
Usually an interface will have multiple case use cases, such as correct use case parameters error use case data null use case different data state use case. Use cases of these different states are defined when defining the interface, and run directly when debugging the interface, which is very efficient.
2. “Data Model” definition and reference
Data models can be defined independently, directly referenced in interface definitions, and referred to each other. The same data structure, only need to define once can be used in multiple places; You only need to modify one place and update multiple places in real time to avoid inconsistency.
3, “automatic verification” data structure during debugging
When using the Apifox debugging interface, the system automatically verifies whether the returned data structure is correct according to the definition in the interface documentation. There is no need to visually identify the data structure, and no need to write the assertion script manually. Very efficient!
4. “Visualize” setting assertions
Set the assertion:
After running, see the result of the assertion:
5. “Visualize” setting extraction variables
6, support database operations
7. “Zero configuration” Mock out very human data
Here’s how Apifox and other tools mock out data with zero configuration:
As you can see, the Apifox zero-configuration Mock is very close to the real data, and front-end development can use it directly without having to write Mock rules manually.
How does Apifox do thatHigh efficiency
,Zero configuration
Generate very user-friendly mock data
- Apifox automatically generates mock rules based on the data structure and data type in the interface definition.
- Apifox has a built-in smart Mock rule library that intelligently optimizes automatically generated mock rules based on field names and field data types. For example, the name contains a string
image
thestring
Type field, automatically mock out an image address URL; Contain stringtime
thestring
Type field, automatically mock out a time string; Contain stringcity
thestring
Type field that automatically mocks out a city name. - Apifox can automatically recognize fields such as picture, profile picture, username, mobile phone number, URL, date, time, timestamp, email, province, city, address, IP and so on according to built-in rules to Mock out very human data.
- In addition to built-in mock rules, users can also customize a library of rules to meet various personalized requirements. Support the use of
Regular expression
,The wildcard
To match the field name custom mock rule.
8. Automatic code generation
According to the interface model definition, Automatically generate business code (Model, Controller, unit test code, etc.) and interface request code in various languages/frameworks (TypeScript, Java, Go, Swift, ObjectiveC, Kotlin, Dart, C++, C#, Rust, etc.). Apifox supports automatic code generation for 130 languages and frameworks.
More importantly, you can customize code templates to generate code that conforms to your team’s architectural specifications for a variety of individual needs.
9. Import and export
- Supports export
OpenApi (Swagger)
,Markdown
,Html
Data format, as can be exportedOpenApi
Format data, so you can take advantage of OpenApi’s (Swagger) rich ecosystem of tools to do all sorts of interface related things. - Support for importing
OpenApi (Swagger)
,Postman
,HAR
,RAML
,RAP2
,YApi
,Eolinker
,NEI
,DOClever
,ApiPost
、Apizza
、ShowDoc
,API Blueprint
,I/O Docs
,WADL
,Google Discovery
And other data formats, convenient old project migration.
Iii. Follow-up function planning
- Interface documents are released to the public.
- Interface performance testing support (similar to JMeter).
- Support plug-in market, you can develop your own plug-ins.
- Supports more interface protocols, such as
GraphQL
,websocket
And so on. - Offline use is supported. The project can be synchronized online (for teamwork) or stored locally (for offline use on a single machine).
4. More Apifox screenshots
Apifox download address
Please visit the Apifox official website: www.apifox.cn/ interface documentation tool
This article is published by OpenWrite!