Skip to content

Latest commit

 

History

History
93 lines (61 loc) · 2.33 KB

README.md

File metadata and controls

93 lines (61 loc) · 2.33 KB

A fake REST server for dashboard

[email protected]

Intro

Why create this repo ?

  • This repo is based on OpenPitrix api spec (built with Swagger), while that api spec is just a design, no mock data. Since you can still use curl to request each swagger api endpoint to populate fake data, but it's verbose, you need hard-code fake data, not programmatically, lack of fun. Meanwhile data structure in swagger spec is not fully usable for our web app, sometimes missing fields, or unreasonable api design.

The advantage of this repo

  • Based on express server and lowdb light-weight json database. We can separate api server from openpitrix dashboard, populate all fake, near-production data programmatically using javascript.

  • Reduce the communication time between font-end devs and back-end devs if the swagger spec is not stable, lack certain fields, or some structures, params are not reasonable.

  • Fake data is fully controlled by front-end devs, generated by Faker.js.

  • Running in docker, can be distributed.

  • Suitable for rapid web app development.

  • Front-end only generate fake json data, this repo will setup all CRUD methods automatically for each api endpoint.

Usage

1. Install from docker hub

docker pull iwisunny/op-mock-server
docker run --name op-mock -p 3000:3000 iwisunny/op-mock-server

2. Build docker image from local

npm run docker

3. Running in local

npm install && ./run.sh

Then open your browser, visit: http://localhost:3000/apps

Or use curl:

curl localhost:3000/apps

Recommend Postman to test api endpoint

APIs

The endpoint's version prefix can be omitted, because we use a rewrite file. So /v1/apps is the same as /apps

/apps

// retrieve all apps
// when filter result, you can append query string: /apps?category=business
GET /apps

// create an app
// when used in code, just put body params in a JS object
// eg: `request.post('/v1/apps', {name: 'k8s', category: 'software'})`
POST /apps

// remove an app
// body params is required.
// code like this: `request.delete('/v1/apps', {app_id: 'app-xxx'})`
DELETE /apps

// update an app
// body params is required.
// example code: `request.patch('/v1/apps', {app_id: 'app-xxx', name: 'docker'})`
PATCH /apps

See all APIs, api.md

License

MIT