Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hokaccha/apimock-middleware
connect middleware for API Mocking.
https://github.com/hokaccha/apimock-middleware
Last synced: about 2 months ago
JSON representation
connect middleware for API Mocking.
- Host: GitHub
- URL: https://github.com/hokaccha/apimock-middleware
- Owner: hokaccha
- Created: 2014-08-12T02:29:11.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-28T02:41:16.000Z (almost 8 years ago)
- Last Synced: 2024-06-21T08:27:56.386Z (6 months ago)
- Language: JavaScript
- Size: 210 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# apimock-middleware
Node.js API Mocking middleware.
inspired by [stubcell](https://github.com/yosuke-furukawa/stubcell)
## Install
```
$ npm install apimock-middleware
```## Usage
server.js
```javascript
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
```yaml
- 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"
```