preface

As the Internet has grown, apis have become critical. According to statistics, there are tens of millions of developers in the market, over 1 billion Internet projects, and a conservative estimate of the number of apis involved is about 10 billion. With such a large base API, it would make sense to address some common pain points. We have summarized the API management issues and found that apI-related documentation, debugging, testing, and data mocks are very inefficient to work with.

Business pain points

The maintenance and management of the interface is time-consuming, taking up about 30% of the development time. Back end programmers have to maintain redundant documentation for themselves, and front end programmers waste a lot of time due to inaccurate documentation provided by back end development.

It is difficult to ensure the correctness and stability of the interface. Front-end engineers write a large amount of exception processing logic to handle various data exceptions. Traditional interface automation testing is very expensive. It may take one day to develop an interface, but it can take several days to write test cases for the interface.

For front-end programmers, they need the interface to Mock back data until the back-end functionality is developed, so that development progress is not affected. Traditional data mock is put simulated data into the project code, it will bring more new problems, first of all, the back-end programmer interfaces defined as demand, architecture involves change at any time, if the front-end programmers fully mock data according to the definition of the original design, will differ greatly and make practical interface.

There is no standardized process for unified processing. This process is very decentralized and needs to cooperate with a lot of tools, resulting in low efficiency.

Market product Research

We expect a complete interface tool to assist developers in debugging, managing documentation and testing interfaces in an easy-to-use GUI interface. So we began to look for similar products in the market. After a period of analysis, we finally found several representative products such as Rap, Nei and easy-Mock. At the same time, we have listed some key characteristics according to our appeal:

Nei is a product of netease’s front-end business Division, which is relatively well done among these products. Nei focuses on saas services and has no open source version. For qunar, the company will not put confidential interface data into a third-party platform.

Rap is a product released by MUX team of Ali Mother in 2013, which is the earliest of its kind in terms of time. Rap is developed by back-end engineers based on Java. If they want to customize some functions, they still need to learn Java, and everyone in our department is not familiar with Java. Rap, on the other hand, has no interface testing capabilities, the back end uses other tools (Postman, Restlet) to test the interface, and the front and back end developers have no uniform tools to use.

Easy-mock is a product produced by the wireless team of Dasoche. Easy-mock is a simulation of interface data, which solves the problem that the front end depends on the back-end interface data. It is a better Mock service among similar products. Easy-mock focuses on the simulation of front-end data, but does not solve the existing problems of Qunar.

Rap and Easy-Mock are single tools for developers that focus on one aspect of the development process rather than addressing the problem from a global perspective. Our goal is to integrate tools in the interface development process. Therefore, we began to independently develop a new interface management platform. We hope that it can provide interface document management, interface data Mock, interface debugging, automated testing and other functions, so as to make the work related to the front and back interfaces more efficient. This is where the YApi interface management platform comes in. Here’s how YApi addresses these pain points.

The solution

  1. Jointly maintain an interface definition to break through various links

In the process of developing interfaces at the back end, development and testing are essential. As shown in the figure below, interface document management has traditionally been isolated because it is not integrated with development and testing, making back-end maintenance a less profitable business for their cumbersome documentation. No one likes to do a low-yield thing, and the only way to really solve this problem is to increase the revenue of maintaining interface documentation.

During interface development, the back end often tests the interface using tools like Postman, which is a necessary part of the development process. If the parameters are changed, the fields and test interface are necessarily updated on tools like Postman. It would be a good idea to have a tool that could be used both as a test interface and as an interface documentation tool, linking the interface documentation to the interface tests. The YApi solution is to connect the interface documents and tests together through a single data source, and if changes are made, because they are made from a single data source, there will be no update delays and delays.

  1. Front-end Mock Server solution

Data Mock services can be tricky in the early stages of development. In most cases, interface request parameters and return data are specified by the back-end. Before the back-end interface is completed, the interface is a black hole for the front end. The initial definition of the interface may be very different from the actual interface made by the back-end. This is where you need a tool that not only simulates the real interface, but also relates the interface document so that you can adjust the interface definition at any time during the back-end development process and notify front-end developers of changes.

In the YApi platform, as long as the response data defined by the interface is maintained on the front and back ends, the required simulation data can be generated. The following code defines the generated data template:

{
    "errcode": 0."errmsg": "@string"."data": {
        "type":"@ pick (1, 2, 3)"."list|1-10": [{
            "uid": "@id"."username": "@name"}}}]Copy the code

The following simulation data can be generated:

{
  "errcode": 0."errmsg": "^ *! SF)R"."data": {
    "type": 2."list": [{"uid": "370000200707276255"."username": "Ruth Clark"
      },
      {
        "uid": "650000200211185728"."username": "Anthony Martin"
      },
      {
        "uid": "370000199201143855"."username": "Laura Rodriguez"
      },
      {
        "uid": "610000198704072775"."username": "Anthony Perez"}}}]Copy the code

In the past, data mocks have affected the project source code. Yapi uses the server proxy solution. You only need to do the server reverse proxy configuration on your development machine, and you can get all the mock data without modifying a single line of the project source code.

The basic Mock tools cover most of the requirements, but some complex scenarios are not possible. For example, when I make a data list page, I need to test the page interaction when a field is at different lengths and the data is empty. YApi provides the ability to expect and customize scripts.

Custom script

Custom scripts can use javascript scripts to customize the data returned based on the request parameters, cookie information. Suppose we have a scenario where I want to control the display of the list page data with cookie “_type”. If _type is error, then the list displays an exception error message. Suppose the _type is empty and the list is empty. This can be achieved using the following code:

if(cookie._type == 'error'){
    mockJson.errcode = 400;
}

if(cookie._type == 'empty'){
    mockJson.data.list = [];
}

Copy the code

3. Automate tests

After interface development is complete, subsequent iterations are very numerous, and each change to the source code requires a large number of tests to ensure that the interface is correct. Human judgment is definitely bad, and the best way to automate tests is to automate them, but automated testing is a very expensive business that requires backend and QA people to learn the frameworks and write a lot of code.

The goal of YApi is to automate tests with a simple GUI interface that is easy to use, even if you don’t understand program development, by configuring parameters and assertions. In addition to the basic functionality, YApi provides powerful pre-script and visual expression capabilities.

Pre-Script

Pre-script includes request parameter processing Script and response data processing Script. Change the parameters of the request and the response data returned by custom javascript scripts. Here’s how it works:

  • Interface request parameters need to be encrypted and response returned to decrypt
  • Interface request parameters need to be added to calculate the token

Visual expression generator

The main purpose of the visual representation is to facilitate user generation of the parameters used in the automated test, through a tree selection, quickly reference the parameter values that depend on. After all interfaces to be tested are configured, click Start Test to test all interfaces in the specified sequence. After the test is complete, you can view the test report.

4. Plug-in mechanism

Business requirements emerge in an endless stream. As a tool for all developers in the country, YApi cannot integrate all the functions required by all developers. We refer to the minimalist product design concept to maintain the simplicity of the kernel and meet the needs of various businesses through flexible and powerful plug-in mechanism. Currently, YApi third-party login, Swagger, Postman data import and other features are implemented based on the plug-in mechanism.

results

Within a week of YApi being launched internally last October, more than 700 developers had joined and used the YApi management interface. There are currently nearly 300 projects within the company that use YApi management, and the average number of mock interfaces is over 5000+ per day. In the spirit of open source, our YApi is open source on Github. At present, there are 1.6K star. Nearly 500 companies in China use YApi to manage their interfaces, including some well-known companies, such as Baidu, JINGdong, Linkou, Kuaishou, Elong, Etc. Vipshop and so on

Access to the address

  • Demo site: yapi.demo.qunar.com
  • github: github.com/ymfe/yapi