Simple Mock JSON Server
SimpleMockServer
Demo | nightly builds | Example | wiki
Introduction
There is a most simple mock server use file organization, just drag your file, and rm your filename,and u got a server;
Direct use
startup your download application,and it will auto create directories named static,apis, and then will start a server, Place the folder that requires Mock in the apis directory, and then start the service, where the api rule is, the directory determines the prefix,[apisuffix]. [apimethod] .json, where apisuffix represents the api path, apimethod represents the interception method, and supports get| post| patch| head| delete| option| put , this is just to keep the results consistent. Index.json is automatically intercepted here as/.
Features
- Returns static JSON data
- Returns based on interface information
- Generated based on the Mock template, see http://mockjs.com/examples.html
Example
PS D:\projects\mock_server> tree .\example\ /f
β .simple-mock.yaml
β [SimpleMockServer] your download application
ββapis
β ββapi
β β index.delete.json
β β index.get.json
β β index.json
β β index.option.json
β β index.patch.json
β β index.post.json
β β querybyentity.json
β β
β ββindex
β test.json
β
ββplugins
β ββpeer-stream
β β index.js
β β package.json
β β pnpm-lock.yaml
β ββnode_modules
ββstatic
bootstrap.min.css
index.html
jquery.min.js
normalize.css
βββββββββ¬ββββββββββββββββββββ¬βββββββββ¬ββββββββββββββββββββββββββββββ
β index β url β method β file β
βββββββββΌββββββββββββββββββββΌβββββββββΌββββββββββββββββββββββββββββββ€
β 1 β api/ β delete β apis\api\index.delete.json β
β 2 β api/ β get β apis\api\index.get.json β
β 3 β api/ β get β apis\api\index.json β
β 4 β api/ β option β apis\api\index.option.json β
β 5 β api/ β patch β apis\api\index.patch.json β
β 6 β api/ β post β apis\api\index.post.json β
β 7 β api/querybyentity β get β apis\api\querybyentity.json β
β 8 β api/index/test β get β apis\api\index\test.json β
βββββββββ΄ββββββββββββββββββββ΄βββββββββ΄ββββββββββββββββββββββββββββββ
and you can fetch /api to access content of apis\api\index.delete.json
Plugins
We also offer a plugin system to extend it, I am writing wiki
Swagger
The Swagger plugin is pre-installed in the project and can be seen directly by visiting /swagger.β€οΈ Many thanks to Elysia for the handy and nice ui . https://github.com/elysiajs/elysia-swagger
Cors
Handles cross-domain issues and can give XHR direct access to Mock's APIsall of plugins can configuration by set field plugins of .simple_mock.yaml
root_dir: .
api_dir: apis
static_dir: static
staticrouteprefix: /
port: 3000
silent:
errorlogfile_path: ./error.log
log_size: 10M
debuglogfile_path: ./debug.log
watch:
- plugins:
- swagger:
- cors:
rewrites:
- path: ''
test: ^(index)$
Configuration
Please see source code ,[WIP]
Check list
- [ x ] Plugin Loaded
- [ x ] Support Static HTML to deploy
- [ x ] Mock JSON by filename
- [ ] WIKI
