# yesman

> Json Mocking Server

Latest version **1.0.8** (published 2015-01-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install yesman
pnpm add yesman
yarn add yesman
bun add yesman
```

Provides the command `yesman`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2015-01-26 |
| First published | 2015-01-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 17 |
| Known vulnerabilities | 0 (+24 in 7 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Kevin Sheedy |
| Maintainers | kevinsheedy |
| Keywords | json, mock, mocking, server |

## Links

- npm: https://www.npmjs.com/package/yesman
- Repository: https://github.com/KevinSheedy/YesMan
- Issues: https://github.com/KevinSheedy/YesMan/issues
- npm.io page: https://npm.io/package/yesman

## Dependencies (17)

- [glob](https://npm.io/package/glob.md) ^4.3.5
- [jade](https://npm.io/package/jade.md) ~1.6.0
- [debug](https://npm.io/package/debug.md) ~2.0.0
- [grunt](https://npm.io/package/grunt.md) ^0.4.5
- [morgan](https://npm.io/package/morgan.md) ~1.3.0
- [wrench](https://npm.io/package/wrench.md) ^1.5.8
- [express](https://npm.io/package/express.md) ~4.9.0
- [request](https://npm.io/package/request.md) ^2.45.0
- [handlebars](https://npm.io/package/handlebars.md) ^2.0.0
- [underscore](https://npm.io/package/underscore.md) ^1.7.0
- [body-parser](https://npm.io/package/body-parser.md) ~1.8.1
- [node.extend](https://npm.io/package/node.extend.md) ^1.1.2
- [json-cascade](https://npm.io/package/json-cascade.md) ^1.0.3
- [cookie-parser](https://npm.io/package/cookie-parser.md) ~1.3.3
- [serve-favicon](https://npm.io/package/serve-favicon.md) ~2.1.3
- [grunt-contrib-watch](https://npm.io/package/grunt-contrib-watch.md) ^0.6.1
- [grunt-express-server](https://npm.io/package/grunt-express-server.md) ^0.4.19

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.8 (latest) — 2015-01-26
- 1.0.7 — 2015-01-26
- 1.0.6 — 2015-01-26
- 1.0.5 — 2015-01-26
- 1.0.4 — 2015-01-23
- 1.0.3 — 2015-01-23
- 1.0.2 — 2015-01-21
- 1.0.1 — 2015-01-21
- 1.0.0 — 2015-01-21
- 0.0.9 — 2015-01-19
- 0.0.8 — 2015-01-19
- 0.0.7 — 2015-01-19
- 0.0.6 — 2015-01-19
- 0.0.5 — 2015-01-15
- 0.0.3 — 2015-01-15
- … 2 more at https://npm.io/package/yesman/versions

## README

# YesMan
Diff based a **mocking server** built on express.js. It is designed for use with RESTful json APIs.

## Overview

Each mocked service has a json template file which defines the structure of the response. Diffs or deltas are then applied to the template to produce the desired response. Both the template and the diffs are pure json.

## Install
```shell
npm install -g yesman
```

## Create a yesman app
```shell
yesman init
```

## Start the yesman server
```shell
yesman start <app-path>
```

## Help
```shell
yesman help
```

## Services / URLs
All available urls are defined in the `services.json` file. Each url points to a folder which contains the template, config and diffs for that service:
```json
{
	"services" : {
		  "/customer"             : "<customer-dir>"
		, "/product"              : "<product-dir>"
		, "/currencies"           : "<currencies-dir>"
	}
}
```


## Forwards
Services can also be configured to forward to an external url in `services.json`:
```json
{
	"forwards" : {
		  "/countries" : "<external-url>"
	}
}
```


## Service Folder
Each service has it's own folder containing templates, config and diffs for that service:

```
customer
    customer-config.json
    customer-template.json
    customer-diff-john-smith.json
    customer-diff-mary-jones.json
```


## Template
A template is pure json and is named <service-name>-config.json. A simple service can function with just a template file and no config file or diff files (see the currencies service). In this case, the template itself is returned unmodified.

For more complex services, multiple diffs can be applied to the template to produce the desired output. See [json-cascade](https://www.npmjs.com/package/json-cascade) for more on how templates work.


## Config
Services are configured in the `<servicedir>/<servicename>-config.json` file. The available configuration values are:

- `verbs` - a list of HTTP request methods for this service eg `["GET", "POST"]`
- `template` - path to the template file relative to the templates folder eg `/customer.json`
- `reqParser` - the name of a function in `req-parsers.js` that will parse the request body and produce a diff to be applied to the template eg the `mirror` function returns the request body itself.
- `mockGenerator` - the name of a function in `dummy-data-generator.js` that will dynamically generate a diff eg timestamps, random number generators etc
- `diff` - path to a custom diff file.
- `states` - list of available states. Each state may override the service level config options: `template`, `reqParser`, `mockGenerator`, `diff`

Any values that are not set explicitly will be defaulted based on the file default-service-config.json.


## States / Diffs
Each service can be put into various states to mimic the behaviour of a stateful application (eg a database). State information is stored as a **diff** in .json file.


## Scenarios
A **scenario** is a list of services and their current states. This allows us to define the behaviour for a particular sequence of service calls. See [scenarios.json](scenarios.json). The scenario under test is set in [config.json](config.json). Changing the scenario in config.json does **not** require a restart.


## Use with Grunt
Yesman can be started via Grunt using the [grunt-express-server](https://github.com/ericclemmons/grunt-express-server) plugin. It can also be restarted automatically as your code changes using the [grunt-contrib-watch](https://github.com/gruntjs/grunt-contrib-watch) plugin. For an example, see [Gruntfile.js](https://github.com/KevinSheedy/YesMan/blob/master/Gruntfile.js)



## foo

Yesman combines data from **4 sources** to build a mock json response.

- **Template** - Defines the structure of the response and some default values.
- **HttpRequest** - Values can be picked from the request and echoed back in the response.
- **Generator** - Values can be generated dynamically eg timestamps
- **State** - Each service can be put into a particular state. For example, for a customer lookup service, the state could be set to: CUSTOMER_FOUND, CUSTOMER_NOT_FOUND, UNAUTHORIZED, SERVER_ERROR

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