apimock-middleware
v0.0.5
Published
Node.js API Mocking middleware.
Downloads
191
Maintainers
Readme
apimock-middleware
Node.js API Mocking middleware.
inspired by stubcell
Install
$ npm install apimock-middleware
Usage
server.js
var http = require('http');
var connect = require('connect');
var bodyParser = require('body-parser');
var apimock = require('apimock-middleware');
var app = connect();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(apimock('apimock.yml'));
http.createServer(app).listen(3000);
apimock.yml
- request:
url: /api/users/:id.json
method: GET
response:
status: 200
file: "json/users/<%= params.id %>.json"
- request:
url: /api/users
method: POST
response:
status: "<%= body.name ? 201 : 422 %>"
file: "json/users/<%= body.name ? 'created' : 'failed' %>.json"