Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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"
```