# router-mock

> mock response data like restful api use router string

Latest version **0.0.4** (published 2018-06-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install router-mock
pnpm add router-mock
yarn add router-mock
bun add router-mock
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2018-06-26 |
| First published | 2018-06-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | MoneyDragon |
| Maintainers | a272121742 |
| Keywords | router, mock, axios, restful |

## Links

- npm: https://www.npmjs.com/package/router-mock
- npm.io page: https://npm.io/package/router-mock

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 0.0.4 (latest) — 2018-06-26
- 0.0.3 — 2018-06-26
- 0.0.2 — 2018-06-26
- 0.0.1 — 2018-06-26

## README

# router mock

## why

Mock response data like restful api use router string, for example:

```javascript
// ajax request use axios
Axios.get('/api/user/10000')
         .then(res => { /* get response res.data */});
// mock response data like restful router
Mock.get('/api/user/:id', id => {
  return { /* return response data */ };
})
```

## how

`mocker` often used in the development environment, if you want the production environment to be the same, you also use it:

```shell
npm i -D router-mock
```

in your `js` files:

```javascript
// es6
import Mock from 'router-mock';

Mock.mock({ /* MockJS template */ });

// mock response data like restful api
Mock.get('/api/users', () => {});
Mock.post('/api/user', () => {});

// dynamic router mock, callback arguments has placeholder params
Mock.get('/api/user/:id', id => {});

// mock a get request with placeholder params
Mock.get('/api/user/:id', (id, params) => {});

// mock a post request
Mock.post('/api/user', data => {});

// response data with sync
Mock.get('/api/user/:id', id => {
  return { /* return response data */ };
});
// response data with async, also you can use client db like rxdb/nedb/minimongo/pouchdb
Mock.get('/api/user/:id', id => {
  return Promise.resolve({ /* return response dataa */ });
});

// set timeout to return response data
Mock.get('/api/users', () => {
  return { /* return response data */ };
}, {timeout: 4000});

// set code to return response data
Mock.get('/api/users', () => {
  return { /* return response data */ };
}, {code: 500});
```

## what

[readme](https://segmentfault.com/a/1190000015219443 '点击阅读')

---
_Source: https://npm.io/package/router-mock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
