# mocker-server

> A server to mock api requests

Latest version **0.0.1** (published 2017-11-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install mocker-server
pnpm add mocker-server
yarn add mocker-server
bun add mocker-server
```

Provides the command `mock-server`.

## 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.1 |
| Published | 2017-11-20 |
| First published | 2017-11-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Ilson Roberto Balliego Junior |
| Maintainers | ilson.balliego |

## Links

- npm: https://www.npmjs.com/package/mocker-server
- npm.io page: https://npm.io/package/mocker-server

## Dependencies (4)

- [nedb](https://npm.io/package/nedb.md) ^1.8.0
- [express](https://npm.io/package/express.md) ^4.16.2
- [commander](https://npm.io/package/commander.md) ^2.11.0
- [body-parser](https://npm.io/package/body-parser.md) ^1.18.2

## Recent versions

- 0.0.1 (latest) — 2017-11-20

## README

# Mocker Server #

A server to easily mock api requests, ideal for situations where you need to test api calls without having the backend server running.  
The server will use nedb to store the requests locally.  
This is not intended to be used in production environment.

## Command line options ##

| Flag | Description |
| ---- | ----------- |
| --config [file] or -c [file] | 'Path to the config file' |
| --save [file] | 'Create a config file with the default configurations'  |
| --port [port] or -p [port] | 'Express port number'  |
| --strict-url |  'Validate model url'  |
| --ttl | Default ttl for mocks, in seconds. ONLY work with strict-url=true |
| --db-path | 'Path to db file'  |
| --in-memory | 'Run using a memory database'  |


## Configuration ##
The configuration will be stored in a json file, if no --config options is used, it will look for a **.mockerserver.json** in the running folder, if there is no default configuration file and no configuration file is specified, the default configurations will be used.

Your configuration should looks like:  
```
{  
  //Specify express port
  "express.port":3000,  

  //Validate the url for the apis
  "mocker.strictUrl":false,  

  //Default ttl for mocks
  "mocker.ttl": 0,

  //Database type, only nedb for now
  "db.type":"nedb",  

  //path to save database files
  "db.url":"mocker.db",  

  //Database specific options
  "db.options":{  
    "inMemoryOnly":false  
  }  
}
```

It is possible to pass the flag --save [file] to save the configuration to a given file


## Usage ##

#### Mock Requests ####

- GET /api/mock/{model}  
Return the listing for the given model

- GET /api/mock/{model}/count  
Return the count for the given model

- GET /api/mock/{model}/{id}  
Return the item that match the id for the given model

- POST /api/mock/{model}  
Insert a new item for the given model

- PUT /api/mock/{model}/{id}  
Update the item that match the id for the given model

- DELETE /api/mock/{model}/{id}  
Delete the item that match the id for the given model


#### Query string filtering ####
The list and counting methods accept filter parameters through query string  

- GET /api/mock/person?filtering={name: 'anderson'}  

Possible filters are:  
- skip=<n>
- limit=<n>
- sort=fieldOne,fieldTwo,-fieldThree  
- filtering=<json formated filter>

#### Model Management ####
if the option --strict-url is used, then is necessary to register the models before utilization

- POST /api/model  { name: "newmodel", ttl: 0 }
Register a new model

- GET /api/model  
Return existent models

- DELETE /api/model/{model}  
Delete a given model


## TODOs and future improvements ##
- Document APIs correctly
- Implement correct filtering instead of using json
- Implement mongodb driver
- Implement TTL for the mocks
- Multi user and Token utilization

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