# chr-mock

> A Koa based the most basic REST mock-server

Latest version **0.3.3** (published 2017-04-01) · MIT license · 0 weekly downloads

## Install

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

Provides the command `chr`.

## 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.3.3 |
| Published | 2017-04-01 |
| First published | 2017-03-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.6 |
| Dependencies | 7 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | chreem |
| Maintainers | chreem |
| Keywords | mock, koa, rest |

## Links

- npm: https://www.npmjs.com/package/chr-mock
- Repository: https://github.com/Chreem/chr-mock
- Homepage: https://github.com/Chreem/chr-mock#readme
- Issues: https://github.com/Chreem/chr-mock/issues
- npm.io page: https://npm.io/package/chr-mock

## Dependencies (7)

- [koa](https://npm.io/package/koa.md) ^2.2.0
- [url](https://npm.io/package/url.md) ^0.11.0
- [path](https://npm.io/package/path.md) ^0.12.7
- [jsonfile](https://npm.io/package/jsonfile.md) ^2.4.0
- [koa-cors](https://npm.io/package/koa-cors.md) 0.0.16
- [commander](https://npm.io/package/commander.md) ^2.9.0
- [koa-bodyparser](https://npm.io/package/koa-bodyparser.md) ^4.2.0

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [tinyspy](https://npm.io/package/tinyspy.md) — 0 weekly downloads
- [@wingtics/connector-mock](https://npm.io/package/@wingtics/connector-mock.md) — 0 weekly downloads
- [@site-spy/mcp-server](https://npm.io/package/@site-spy/mcp-server.md) — 0 weekly downloads

## Recent versions

- 0.3.3 (latest) — 2017-04-01
- 0.3.2 — 2017-03-31
- 0.3.1 — 2017-03-29
- 0.3.0 — 2017-03-29
- 0.2.5 — 2017-03-22
- 0.2.4 — 2017-03-21
- 0.2.3 — 2017-03-21
- 0.2.2 — 2017-03-21
- 0.2.1 — 2017-03-21
- 0.2.0 — 2017-03-19
- 0.1.1 — 2017-03-19
- 0.1.0 — 2017-03-18

## README

# chr-mock

A simple Koa based mock-server, provide the most basic REST service on watch a js/json file ~~for myself~~.:no_mouth:  
[![chr-mock](https://img.shields.io/npm/v/chr-mock.svg?style=flat-square)](https://www.npmjs.com/package/chr-mock)
[![David](https://img.shields.io/david/Chreem/chr-mock.svg?style=flat-square)](https://david-dm.org/Chreem/chr-mock)
[![npm](https://img.shields.io/npm/l/chr-mock.svg?style=flat-square)](https://www.npmjs.com/package/chr-mock)
[![Travis](https://img.shields.io/travis/Chreem/chr-mock.svg?style=flat-square)](https://travis-ci.org/Chreem/chr-mock)
[![Coveralls](https://img.shields.io/coveralls/Chreem/chr-mock.svg?style=flat-square)](https://coveralls.io/github/Chreem/chr-mock)

## Usage

```bash
$ npm i -g chr-mock
$ chr

  Usage: index [options] [command]


  Commands:

    watch [file]  Add a file to watch

  Options:

    -h, --help      output usage information
    -p, --port <n>  Add port to listen, default is 4000

# Default file path is ./test/data.test.json
$ chr watch
~/test/data.test.json is watched
```

## Method for now

Just one level provided: `/tablename/id`, because of the lazy author.  

### TODOs

* ~~get: http://***/tablename?page=2&limit=10.~~
* ~~get: http://***/tablename/id or tablename?name=value etc...~~
* ~~post: could change element too.~~

### get

```bash
http://127.0.0.1:4000/tablename[/id/][?name=value]

http://127.0.0.1:4000/images
http://127.0.0.1:4000/images/1
http://127.0.0.1:4000/images?name=png
```

* just has tablename  
    The results of tablename's all datas.
* tablename/id  
    ~~Nothing to say.~~
* data filter  
    When querys were followed with tablename, data would be filted by all key-value pair in querys.  

#### Notice

1. If query key is `id`, filter would be exact matching, others was fuzzy.
2. These were keywords of query to reserve: `page`, `limit`, `asc`, `desc`. These would be used in the near future. ~~maybe😝~~

### post

```http
POST http://127.0.0.1:4000/tablename
Content-Type: application/json

{ "id":"1","hehe":"123" }

###

POST http://127.0.0.1:4000/tablename?name=png
Content-Type: application/json

{ "id":"1","hehe":"123" }
```

* without query: use the default keyword `id` to match data, if not even id, it would be added following by the last object in json file.
* with query: query first, query > `id`!!!, if both query and body.id was setted, it would just match query. To solve this, follow query `?id=*`.
* query match is the same with get#Notice.
* result is Object.assign(origin, new).

### patch

one thing different with post, it could not add new element.

### delete

```md
DELETE http://127.0.0.1:4000/tablename
Content-Type: application/json

{ "name":"png","hehe":"123" }
```

* delete without query params. filter is working on body, of course the same with get#Notice query.
* result were all deleted elements.

## Thank for

Teacher Ryan: [ryan2-cli](https://www.npmjs.com/package/ryan2-cli)  
Others in

## LICENSE

[MIT](https://github.com/Chreem/chr-mock/blob/master/LICENSE)

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