mock-responses
NodeJS http request handling middleware, a mock server, with admin UI.
Is your back-end api not ready, too slow, or unstable?
Your front-end development is dependent on several APIs and they affect your development?
You don't have to wait any more by mocking all back-end responses using mock-responses
.
Compatible with;
![image](https://user-images.githubusercontent.com/1437734/44070798-cd75a576-9f53-11e8-86f7-d902393aa35e.png)
TL;DR
Add the middleware to your code before you start the server.
var express = require('express');
var mockResponses = require('mock-responses')('./mock-responses.sqlite3');
var app = express();
app.use(mockResponses);
app.listen(3000);
Then, hit the urls
http://localhost:3000/developer
http://localhost:3000/my/api/path
Install
$ npm install --save-dev mock-responses
Getting Started
1. Start your development server with mock-responses middleware
express
example
const express = require('express');
const path = require('path');
const mockResponses = require(__dirname + '/../index.js');
const app = express()
mockResponses.forEach(mw => app.use(mw))
app.listen(3000, () => console.log('Example app listening on port 3000!'))
2. Visit admin UI /developer#mock-responses
to manage mock or proxy responses.
https://localhost:3000/developer#mock-responses
proxy-url options can be found here
3. DONE!!
Now, you can add, update, delete, or search your api responses, which is mocked but never fails.
function response example
To use function, please set response content type as text/javascript
function(req, res, next) {
if (req.query.foo == 1) return serveResponse(7);
else if (req.query.foo == 2) return serveResponse(8);
else if (req.query.foo == 3) return serveResponse(9);
else return false;
}
Compatible servers
mock-responses
is compatible with the following servers:
License
The MIT License (MIT)
Copyright (c) 2018 Allen Kim