# json-service-mocker

> A client-side XHR mocker specifically for mocking JSON data from an API. It replaces the global XMLHttpRequest with MockXMLHttpRequest.

Latest version **1.0.5** (published 2017-09-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install json-service-mocker
pnpm add json-service-mocker
yarn add json-service-mocker
bun add json-service-mocker
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2017-09-18 |
| First published | 2017-09-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | manuel yang |
| Maintainers | mannyyang |
| Keywords | json, service, mocker, client-side, XHR, XMLHTTPRequest, API, javascript |

## Links

- npm: https://www.npmjs.com/package/json-service-mocker
- Repository: https://github.com/mannyyang/json-service-mocker
- Homepage: https://github.com/mannyyang/json-service-mocker#readme
- Issues: https://github.com/mannyyang/json-service-mocker/issues
- npm.io page: https://npm.io/package/json-service-mocker

## Dependencies (2)

- [nise](https://npm.io/package/nise.md) ^1.0.1
- [text-encoding](https://npm.io/package/text-encoding.md) ^0.6.4

## 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.5 (latest) — 2017-09-18
- 1.0.4 — 2017-09-18
- 1.0.3 — 2017-09-15
- 1.0.1 — 2017-09-15
- 1.0.0 — 2017-09-15

## README

# json-service-mocker
A client-side XHR mocker specifically for mocking JSON data from an API. It replaces the global XMLHttpRequest object with one provided by sinon's [nise](https://github.com/sinonjs/nise) tool.

# Requirements
This package uses Object.assign so that must be available either through a polyfill or supported browsers.

# Installation
```
npm install json-service-mocker
```

# Usage
To use inside of your project, import it like so:

```
///////////////////////////////////
/* --- Importing the library --- */
///////////////////////////////////

// Typescript
import { JSONServiceMocker } from 'json-service-mocker';

// ES6
const JSONServiceMocker = require('json-service-mocker').JSONServiceMocker;

//////////////////////////////////////////
/* --- Initializing mocking service --- */
//////////////////////////////////////////

const services = [
    {...},
    {
        'method': 'GET',
        'path': '/get/json',
        'status': 200,
        'body': {
            'item': {
                'name': 'me',
                'age': 2
            },
            'secondItem': {
                'name': 'me'
            }
        },
        'timeout': '',
        'header': ''
    },
    {...}
];

const mocker = new JSONServiceMocker();
mocker.init(services);
```

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