Skip to content

Latest commit

 

History

History
189 lines (116 loc) · 6.88 KB

README.en.md

File metadata and controls

189 lines (116 loc) · 6.88 KB

API Management Surface - API Mocker

API Mocker does not only mock the API, it aims to improve front-end and back end cooperative development by providing a unified API management, and a platform to communicate iterative improvments and maintainence of the API.

Click to view live example ==> DEMO

Note: The provided demo demonstrates the look and feel of the project but does not gurantee data security and stability, and may even delete data periodically. Do not use the demo for personal or business projects


Contents

System Functionality

API Conventions

API Mocker provides a user friendly yet powerful API editior, users can easily define various API behaviors such as:

  • Structured parameter input and output
    • Support different request parameter types (querybodypath, header)
    • Strict parameter checking
    • Support for data types(stringnumberbooleanobjectarray)
    • 参数备注、示例
  • support JSON parsing
  • maintains history data

demo screenshot

Mock data

API Mocker believes that the defined mock api should not only be enforced on the response but also in the request conventions. Thus, we provide a production quality mock service

  • Mock requests generates fake data based on defined rules
  • Mock api will check the reqest parameters from rules (Check for optionals or correct parameter types)
  • Able to mock various real-life responses such as 200, 404, 500 based on user settings
  • Support proxy requests from live or testing evironments, for separation of development environments excluding charles proxy
  • supports Mock.js grammar and conventions

API documentation

API Mocker automatically generates concise, well-structured interface documents based on defined rules. You can also subscribe to API changes individually or in subscription groups, to receive an email when any interface in the subscription list have been added, modified or deleted.

screenshot of api documentation

API Authorisation

API Mocker provides convinient access control

  • group level api control
  • retrieve and write control

Other capabilities

  • API testing: developers can conviniently test the API instead of repeatedly filling up fields with request tools like postman
  • Convinient API search (search by url, administrators, etc.)
  • support import from RAP

Technology stack and third party libraries

  • ES6
  • ESLint (Standard)
  • Ramda

Client

Server


Getting Started

Installation requires certain external commands(mongod)

  • make install

This command will also ensure the startup process of mongod. If it is not started, it will create the db directory locally and start mongod. If the server is booted up, re-execute make install to ensure the database is started.

Server Configuration

To start the project for the first time, you need to manually add the configuration files ./server/config/core.js and ./server/config/manager.js

You can quick start by duplicating ./server/config/default.core.js and ./server/config/default.manager.js respectively

Note: core.js contains the configurations for mongo database, md5 key, mail service; manager.js is for initializing new super administrator account.

Deployment (dev)

Client

  • make client or cd client && npm install && npm run dev

Server

  • make server or cd server && npm install && npm run dev

Deployment (prods)

Client

  • make prod_client or cd client && npm install && npm run build

Server

  • make prod_server or cd server && npm install && npm start

Default port number is 7001


Deployment Notes

Environment requirements

"node": ">= 6.0.0",
"npm": ">= 3.0.0"

Config - Server

If you require https support, the certificate paths is sent in server/index.js. Other server configurations are in the server/config such as:

clientRoot: client address, currently only used in sending reminder emails;

transporter: For mail-related configuration, please set your own push mailbox. Some mail service providers have a high security policy and push errors occur. Please test them yourself. If not configured, the system does not push the email;

pushInterval: The mail push interval timings. Currently only this configuration is modified for the api;

mongoose: related configuration of mongoDB;

bodyParser.jsonLimit: The maximum limit for api request information. Because the amount of data is relatively large when the api is updated, you have to define the limit.

For other configurations, please see the file comments and related content. in the egg.js documentation

Config - Client

The client is configured in client/config/index.js. among them:

docsUrl: The document address, which can be configured to its own git repository;

serverRoot: server interface root path;

assetsPublicPath: Static file public path, all static file resource addresses, starting with this path. Please configure according to your own release requirements.

For other related configurations, please refer to the vue-cli scaffolding [webpack template] (https://github.com/vuejs-templates/webpack)

Example Deployment with nginx

Suppose the api-mocker project folder path is __api_mocker_path

With the domain name your-mocker.com

  1. Deploy (prods), please refer to the above commands
  2. nginx add configuration:
server {

        listen       80;
        server_name  localhost;

        location /mock-api/ {
            proxy_pass http://127.0.0.1:7001/;
        }

        location /mock {
            autoindex on;
            alias __api_mocker_path/client/dist;
        }
}
  1. modify the config of serverRoot under client/config/index.js to your-mocker.com/mock-api
  2. visit http://your-mocker.com/mock

Note: If the server bandwidth is low, you can deploy the client to cdn, configure the route, and re-update the index.html file cache under the dist directory, Or just synchronize the client/dist/static directory to cdn, and then do the forwarding configuration for your own nginx.