# upstream-api

> Easily create static upstream dummy APIs for use in testing.

Latest version **1.0.1** (published 2019-06-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install upstream-api
pnpm add upstream-api
yarn add upstream-api
bun add upstream-api
```

## 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 | 2019-06-19 |
| First published | 2019-06-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | JoeScho |
| Maintainers | joescho |
| Keywords | test, api, server |

## Links

- npm: https://www.npmjs.com/package/upstream-api
- npm.io page: https://npm.io/package/upstream-api

## Dependencies (2)

- [express](https://npm.io/package/express.md) ^4.16.4
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.13.1

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-06-19

## README

# upstream-api
This creates a locally hosted upstream API, for use in testing.

## Usage
```js
const needle = require('needle');
const { startServer } = require('upstream-api');
const config = require('testapi-config.json');

startServer(config);

const res = await needle('get', 'http://localhost:8000/test');

// res.status: 200
// res.headers: { 'x-correlation-id': 'abc123' }
// res.body: {
//   success: true,
//   foo: 'bar'
// }
```

## Config
These are the possible configuration options:

| name | description | example | required |
| ---- | ----------- | ------- | -------- |
| port | The port to host the server on | 8000 | yes |
| endpoints | An array of endpoints to host on the server | see full example | yes |
| endpoints[n].path | The path (without '/') of the endpoint | 'test' | yes |
| endpoints[n].method | The method of the endpoint | 'get' | yes |
| endpoints[n].status | The statusCode to be returned | 200 | yes |
| endpoints[n].delay | The delay (in ms) of the endpoint | 200 | no |
| endpoints[n].body | The response body to be returned | { foo: 'bar' } | no |
| endpoints[n].headers | An array of headers to be set on the response | [{ 'x-correlation-id': 'abc123' }] | no |

### Example Config

#### Config
```json
{
  "port": 8000,
  "endpoints": [
    {
      "path": "test",
      "method": "get",
      "status": 200,
      "delay": 200,
      "body": {
        "success": true,
        "foo": "bar"
      },
      "headers": [
        { "x-correlation-id": "abc123" }
      ]
    }
  ]
}
```

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