stubon is simple dummy api server.
$ npm i -D stubon
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!'
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);
$ $(npm bin)/stubon -p 8080 -s ./dev/src --debug --ssl
$ open https://localhost:8080/aaa/get
If 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