stubon
v0.5.2
Published
stubon is simple dummy api server.
Readme
Stubon
stubon is simple dummy api server.
0. install
$ npm i -D stubon1. Make source file by JSON or YAML or both.
When "http request" includes all condition that written under "request", value returned that under correspond "response.body". Sample is here.
// ./dev/src/dummy.yml
'/aaa/get':
-
request:
method: 'GET'
response:
status: 200
body:
result: 'OK!'2. Create server.
2.1 The way to make with a file.
var Stubon = require('stubon').default; // = import Stubon from 'stubon';
var srcPath = './dev/src';
var stubon = new Stubon(srcPath, {
debug : true,
ssl : true,
});
stubon.server().listen(8080);2.2 The way to make with a command line.
$ $(npm bin)/stubon -p 8080 -s ./dev/src --debug --ssl3. Call a dummy API.
$ open https://localhost:8080/aaa/getIf you call API from node script, you need setting option 'agent'. When you call from browser, you can do permission setting on the browser side.
// call_api.js
fetch('https://localhost:8080/aaa/get', {
agent : new https.Agent({ rejectUnauthorized : false }),
})
.then(function(res) {
return res.json();
})
.then(function(json) {
console.log(json.result); // OK!
});$ node call_api.js