# tinystub

> Stub server for http end to end testing. Request determines response http status code, body and headers.

Latest version **1.0.1** (published 2017-01-22) · MIT license · 0 weekly downloads

## Install

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

## 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.1 |
| Published | 2017-01-22 |
| First published | 2016-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Neil Sarkar & Super Serious Company |
| Maintainers | neilsarkar |
| Keywords | stub, end to end, api, testing, mock, server |

## Links

- npm: https://www.npmjs.com/package/tinystub
- Repository: https://github.com/superseriouscompany/tinystub
- Homepage: https://github.com/superseriouscompany/tinystub#readme
- Issues: https://github.com/superseriouscompany/tinystub/issues
- npm.io page: https://npm.io/package/tinystub

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) ^2.4.4
- [express](https://npm.io/package/express.md) ^4.14.0
- [body-parser](https://npm.io/package/body-parser.md) ^1.15.2

## 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
- [@anil-labs/factory](https://npm.io/package/@anil-labs/factory.md) — 0 weekly downloads
- [@massiv-oss/grpc-fake-server](https://npm.io/package/@massiv-oss/grpc-fake-server.md) — 0 weekly downloads
- [@buoy-gg/location](https://npm.io/package/@buoy-gg/location.md) — 0 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-01-22
- 1.0.0 — 2016-12-19

## README

# tinystub

A tiny stub server inspired by the functionality of <a href="https://httpbin.org">httpbin.org</a> for use in black box testing of JSON APIs.

## Usage:

```js
const stub       = require('tinystub');
const stubHandle = stub(3001); // specify port on localhost
```

```bash
#returns 200 with empty body
$ curl http://localhost:3001

# returns 200 with body of {"cool": "nice"}
$ curl -H "Content-Type: application/json" -XPOST http://localhost:3001/somepath -d '{"cool": "nice"}'

# returns 403 with body of {"error": "permission denied"}
$ curl -H "Content-Type: application/json" -XPOST http://localhost:3001/some/nested/path?status=403 -d '{"error": "permission denied"}'

# clears calls
$ curl -XDELETE http://localhost:3001
```

```js
console.log(stubHandle.calls.length);  // 3
console.log(stubHandle.calls[0].url);  // /some/nested/path
console.log(stubHandle.calls[0].body); // {"error": "permission denied"}

stubHandle(); // shuts down server
```

Run with `DEBUG=tinystub` to see all requests.

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