I recently wanted to write an interface document for a project, and the first thing that came to mind was Swagger. I didn’t realize that Swagger 2 was unfriendly to Spring5’s reactive programming, so I looked for something better

Introduction and Installation

Rap2 is the open source interface management tool RAP from the Alimoma front end team, which is currently in its second release. The advantage of RAP2 is that it can easily manage a full set of standard interface documents while also providing MockJS data. This eliminates the need for the back end to “get to the bottom” and the front end to start development, both improving team efficiency and reducing the coupling between the front and back ends

The installation

The latest version of RAP2 officially provides two installation methods, and the first docker deployment method is strongly recommended, which is simple and direct. Here is the installation process

steps

  1. Local Environment Requirements

    Install the Docker

  2. Pull rap2 project to any local directory (note: project includes redis, mysql)

    git clone [email protected]:thx/rap2-delos.git
    Copy the code
  3. Enter the project and modify the docker-compose. Yml file, personally modify as needed. Here I directly use redis and mysql in the project, and change the mapping port in order not to conflict with the local.

    // ...
    services:
      # frontend
      dolores:
        image: rapteam/rap2-dolores:latest
        ports:
          You can customize the front-end port number before the colon. Do not move after the colon38081-4000: / /... redis: image: redis:4 ports: - 6479:6379 // ... Mysql: image: mysql: 5.7# expose 33306 to client (navicat)
        ports:
           - 3406:3306
    Copy the code
  4. Pull image and start (note: the following command is executed in the rap directory)

    docker-compose up -d
    Copy the code
  5. Initialize mysql database manually for the first time (note)

    docker-compose exec delos node scripts/init
    Copy the code
  6. Access after the deployment is successful

    http://localhost:4000 # front-end http://localhost:38080 # back-end

  7. Others: Disable the RAP service

    docker-compose down
    Copy the code

For details about manual deployment, see the official website

Configure a user-defined interface in RAP2

steps

  1. Front – end login http://localhost:4000/

  2. New warehouse in upper right corner

  1. Create a module -> Create an Interface

  1. Click Import and paste the sample JSON directly

  1. At this point, a basic interface document is complete

The mock data

It’s easy to import json directly, but the simulated data is fixed. Those of you familiar with mockJs know that dynamic response data is better suited for development debugging. Fortunately, rap also supports the mocking. Js syntax specification

See official Git for detailed syntax rules, or the official example (recommended). The following are just a few additions to the usual examples:

type Generate rules The initial value scenario
Number @natural Random number generation
Number 1-10 Random numbers from 1 to 10
String @name Random English name
String @cname Random Chinese name
String @city Random name of a domestic prefecture-level city
Function @datetime(“yyyy-MM-dd HH:mm:ss “) Date in the specified format

As you can see, the use of these initial values is either @ placeholder or @ placeholder (parameter [, parameter])

type A placeholder note
The Basic class is a Basic class. boolean, natural, integer, float, character, string, range, date, time, datetime, now
Image (Image) image, dataImage Picture address
Color value color A hexadecimal string
Text paragraph, sentence, word, title, cparagraph, csentence, cword, ctitle Paragraphs, headings, etc
Name first, last, name, cfirst, clast, cname The first name, last name and first name placeholders are preceded by C to generate Chinese data
Web url, domain, email, ip, tld Address, domain name, email, IP address
Address area, region Area, direction
Helper capitalize, upper, lower, pick, shuffle
Miscellaneous guid, id

The sample

export

  • After finishing the interface module, click the export button under the navigation bar to make the document or script, which is very convenient

Problems encountered

  1. When RAP2 was running, there was a problem with the login on the front-end page. The token was invalid during the login, and the registration did not respond. Later, I simply emptied the Loggers table in RAP2 project

  2. By default, mysql does not have a password when rap2 is installed, so just press enter when logging in

    Enter mysql.mysql
    docker exec -it docker_mysql mysql -uroot -p
    # Set password
    mysql> SET PASSWORD FOR 'root' = PASSWORD('new_password');
    Copy the code
  3. Modify docker-compose. Yml, and go to Step 5 again