I would like to mock the backend for quicker development by providing json response without reling on the real backend. The frontend app is an Angular app and we use Gulp as a development and build tool.
E.g. have a specific api (.../custumers/123) return a static json result.
Is there perhaps already a gulp tool for this?
I went with json-server and gulp-json-srv which I think had some benefits of simplicity and quick setup.
gulpfile.js config to start json-server and to proxy the http calls using a "gulp mock" task:
gulp.task('mock', ['connect-mock'], function () {
jsonServer.start({
data: 'db.json',
port: 8087
});
});
gulp.task('connect-mock', function () {
connect.server({
port: 8085,
livereload: true,
middleware: function (connect, o) {
return [(function () {
var url = require('url');
var proxy = require('proxy-middleware');
var options = url.parse('http://127.0.0.1:8087');
options.route = '/v2';
return proxy(options);
})()];
}
});
});
db.json with mocked data:
{
"customers": [
{ "id": 1, "name": "Johnny B" },
{ "id": 2, "name": "Steve G" },
{ "id": 3, "name": "Glenn H" }
]
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments