svrx-plugin-json-server
The svrx plugin for json-server, help us to get a full fake REST API with zero coding and integrated with svrx.
Usage
Please make sure that you have installed svrx already.
Example beblow need a
db.json
in your current working directory, and with content likeposts:id: 1 title: 'json-server' author: 'typicode'id: 2 title: 'json-server' author: 'typicode2'
Via CLI
svrx -p json-server
Via API
const svrx = ; start;
route.js
Then Play it in your This plugin will register a route action named jsonServer
which can help to proxy specified request to json-server
see svrx routing dsl(中文文档) for more details
to;
Now, all request will be proxy to json-server.
Visit page /posts/1
in your browser, you will
found that the corresponding post object has been output, like
id: 1 title: 'json-server' author: 'typicode'
request rewrite
By action rewrite, you can also rewrite request before proxy to json-server
to// /api/posts > /posts
And More...
See official json-server reference for more details about json-server
Options
source [String|Object]:
The source of json server , can be an object or string, default is db.json
;
;
proxy [String|RegExp|Function]:
A regular expression string or filter function that represents a matching rule to proxy request to json-server.
;
In a simple usage, you can use this option instead of manually declaring a route.
logger [Object]:
Enable json-server logger (default: false)
License
MIT