# bogus-api

> Mock API server for front-end development

Latest version **1.0.0** (published 2015-11-28) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2015-11-28 |
| First published | 2015-11-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 4.0.0 |
| Dependencies | 6 |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| Author | Cameron Nokes |
| Maintainers | ccnokes |
| Keywords | JSON, server, fake, REST, API, prototyping, mock, mocking, test, testing, rest |

## Links

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

## Dependencies (6)

- [chalk](https://npm.io/package/chalk.md) 1.1.1
- [express](https://npm.io/package/express.md) 4.13.3
- [http-proxy](https://npm.io/package/http-proxy.md) 1.12.0
- [json-server](https://npm.io/package/json-server.md) git+https://github.com/ccnokes/json-server.git
- [serve-index](https://npm.io/package/serve-index.md) 1.7.2
- [require-directory](https://npm.io/package/require-directory.md) 2.1.1

## 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.0 (latest) — 2015-11-28

## README

# Bogus API

A wrapper around the great [json-server](https://github.com/typicode/json-server). It allows you to specify multiple REST resources. Pass in a directory of Javascript files to be required, and they become your REST endpoints.

### Install
```
npm install bogus-api
```

### Usage
```javascript
require('bogus-api').create().start({
    resourceDir: './my-resources',
    resourceUriPrefix: '/api/v1',
});
```

Each JS file in the `my-resources` directory could look like:
```javascript
var users = [];
// Create 10 users
for (var i = 0; i < 10; i++) {
    users.push({ id: i, name: 'user' + i });
}
module.exports = users;
```

Or it could look like:
```javascript
module.exports = [
    { "id": 1, "title": "json-server", "author": "typicode" },
    { "id": 2, "title": "test", "author": "ccnokes" }
];
```
So you get a little more flexibility than with plain `json-server`.


You can add or override routes using the Express API like so:
```javascript
bogusAPI = require('bogus-api');
var bogusServer = bogusAPI.create({
    // These routes will get mounted before the resources are, allowing you to "short-circuit" them
    // This is useful for testing how the UI reacts to error states from an API
    priorityRoutes: function(server) {
        // the server arg is an instance of an Express server
        server.get('/someRoute', function(req, res) {
            res.status(500).send({ message: 'Some error.' });
        });
    }
}).start();
```

## Options

| Option            | Description  |
| ----------------- |--------------|
| port              | Port the app runs on. 7001 by default. |
| host              | 0.0.0.0 by default. |
| resourceUriPrefix | Prefixes all resources with a URI. |
| resourceDir       | Directory containing your resources. Default to sample-resources. |
| proxy             | Object containing the host and port of the URL to proxy to. No default. |
| staticDir         | Path to static directory to serve. |
| staticUri         | URI to serve static directory through.  |

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