# stubmatic

> Mock HTTP calls without coding. Designed specially for testing and QAs.

Latest version **5.4.1** (published 2019-02-14) · MIT license · 0 weekly downloads

## Install

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

Provides the command `stubmatic`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 5.4.1 |
| Published | 2019-02-14 |
| First published | 2016-12-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 12 |
| Unpacked size | 106.1 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | yes |
| GitHub stars | 131 |
| Author | Amit Kumar Gupta |
| Maintainers | amitgupta |
| Keywords | skeleton, stubby, stub, stubmatic, soap, restful, REST, SOAP, mock, http, https, ssl, gzip, simulator, tcp, proxy, fake, validate, validator, msgpack, nimn |

## Links

- npm: https://www.npmjs.com/package/stubmatic
- Repository: https://github.com/NaturalIntelligence/Stubmatic
- Issues: https://github.com/NaturalIntelligence/Stubmatic/issues
- npm.io page: https://npm.io/package/stubmatic

## Dependencies (12)

- [hashes](https://npm.io/package/hashes.md) ^0.1.3
- [nimnjs](https://npm.io/package/nimnjs.md) ^2.2.0
- [yamljs](https://npm.io/package/yamljs.md) ^0.2.8
- [js-joda](https://npm.io/package/js-joda.md) ^1.9.2
- [winston](https://npm.io/package/winston.md) ^2.4.4
- [jsonlint](https://npm.io/package/jsonlint.md) ^1.6.3
- [http-proxy](https://npm.io/package/http-proxy.md) ^1.17.0
- [deep-assign](https://npm.io/package/deep-assign.md) ^2.0.0
- [notepack.io](https://npm.io/package/notepack.io.md) ^2.2.0
- [fast-xml-parser](https://npm.io/package/fast-xml-parser.md) ^3.12.13
- [fast-lorem-ipsum](https://npm.io/package/fast-lorem-ipsum.md) ^1.2.0
- [nimn-date-parser](https://npm.io/package/nimn-date-parser.md) ^1.0.0

## 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
- [@enky-yy/fauxmcp](https://npm.io/package/@enky-yy/fauxmcp.md) — 0 weekly downloads
- [fake-bolt11](https://npm.io/package/fake-bolt11.md) — 0 weekly downloads
- [@sgedda/mockifyer-generator](https://npm.io/package/@sgedda/mockifyer-generator.md) — 0 weekly downloads

## Recent versions

- 5.4.1 (latest) — 2019-02-14
- 5.4.0 — 2019-02-10
- 5.3.1 — 2019-01-18
- 5.3.0 — 2019-01-04
- 5.2.5 — 2019-01-03
- 5.2.4 — 2018-12-01
- 5.2.3 — 2018-12-01
- 5.2.0 — 2018-06-11
- 5.1.1 — 2018-04-26
- 5.1.0 — 2018-03-08
- 5.0.6 — 2018-01-31
- 5.0.5 — 2017-06-25
- 5.0.4 — 2017-03-25
- 5.0.3 — 2017-03-04
- 5.0.2 — 2017-03-02
- … 5 more at https://npm.io/package/stubmatic/versions

## README

# Stubmatic
Mock HTTP calls without coding. Designed specially for testing and testers.

[![NPM quality][quality-image]][quality-url]
[![Travis ci Build Status](https://travis-ci.org/NaturalIntelligence/Stubmatic.svg?branch=master)](https://travis-ci.org/NaturalIntelligence/Stubmatic) 
[![Gitter](https://img.shields.io/gitter/room/Stubmatic/Stubmatic.svg)](https://gitter.im/Stubmatic/Lobby#) 
[![Known Vulnerabilities](https://snyk.io/test/github/naturalintelligence/stubmatic/badge.svg)](https://snyk.io/test/github/naturalintelligence/stubmatic) 
[![bitHound Overall Score](https://www.bithound.io/github/NaturalIntelligence/Stubmatic/badges/score.svg)](https://www.bithound.io/github/NaturalIntelligence/Stubmatic) 
[![Code Climate](https://codeclimate.com/github/NaturalIntelligence/Stubmatic/badges/gpa.svg)](https://codeclimate.com/github/NaturalIntelligence/Stubmatic) 
[![Coverage Status](https://coveralls.io/repos/github/NaturalIntelligence/Stubmatic/badge.svg?branch=dev)](https://coveralls.io/github/NaturalIntelligence/Stubmatic?branch=dev)

<a href="https://www.patreon.com/bePatron?u=9531404" data-patreon-widget-type="become-patron-button"><img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" alt="Become a Patron!" width="200" /></a>
<a href="https://www.paypal.me/amitkumarguptagwl"> <img src="https://www.paypalobjects.com/webstatic/en_US/btn/btn_donate_92x26.png" alt="Stubmatic donate button"/></a>


[quality-image]: http://npm.packagequality.com/shield/stubmatic.svg?style=flat-square
[quality-url]: http://packagequality.com/#?package=stubmatic


<img align="right" src="https://naturalintelligence.github.io/Stubmatic/img/stubmatic_logo.png?raw=true" width="180px" alt="Stubmatic logo"/> 

1. Installation : `$npm install stubmatic -g`
2. Set up repo  : `$stubmatic init [repo-name]`
3. Start server : `$stubmatic [-d <repo-name>]`
4. Help         : `$stubmatic --help`

Important links : [Video Tutorial](https://youtu.be/7mA4-MXxwgk), [Wiki](https://github.com/NaturalIntelligence/Stubmatic/wiki), [NPM](https://www.npmjs.com/package/stubmatic), [Demo](https://github.com/NaturalIntelligence/Stubmatic/tree/master/functional-tests) application, [issues](https://github.com/NaturalIntelligence/Stubmatic/issues), [changelogs](https://github.com/NaturalIntelligence/Stubmatic/wikiChangelog)
[<img width="180px" src="https://naturalintelligence.github.io/Stubmatic/img/showcase_btn.png" alt="Stubmatic donate button"/>](https://naturalintelligence.github.io/Stubmatic/#showcase)

## Main features

* Mock HTTP(s) calls. (Hence can mock REST/SOAP web services)
* Inspect HTTP calls from CLI or log them for more detail.
* No code. Designed specially for testing and testers.
* Mock messagepack or Nimn (निम्न) response easily. Write in JSON parse in desirable format. 
* Support SSL certificates.
* Optional configuration
* Dynamic response
  * Use Regular Expressions to match a request, capture some part of the request, to decide response file at runtime, to change contents of response at runtime etc. 
  * Use **Expressions** (functions and markers) to display dynamic dates, random number etc.
  * Devide your response into multiple files (called **dumps**) for readability, reusability, and consistency.
  * Create a response skeleton with **DB sets** and fill data as per matched request.
  * Delay response for fixed or random time.
* Send response as a stream (downloadable file)
* Compress response automatically.
* Route requests to other server using **proxy**.
* Memory and CPU efficient
* Ready to be used in performance environment
* And much more like short notations, multiple mapping files, file strategy etc.

## Configuration
To install stubmatic, you need to install [nodejs](https://nodejs.org/en/download/) and npm first. It is recommanded to be on latest version of both. npm is bundeled with nodejs. Now follow above commands to install stubmatic and to set up a repo.

## How to start
Stubmatic works on request response mappings specified in a yaml file. Response contents can be read from *body* or *file* attribute of a maping. 

```yaml
-  request:
      url: /stubs/(admin|staff|customer|security)/([0-9]+)/2

   response:
      body: >
        multiple line response
        another line
```
When a request reaches to stubmatic server, it matches the request against all mappings. Whichever mapping matches first(top to bottom), will be used to serve the response. A complete response can be built with multiple files. It can also have some placeholder to show dynamic data, like date, or some random number or some part from request itself. Stubmatic first process and build complete response then respond back to any HTTP(s) request.

Using regular expression, single mapping can be used to match multiple requests and serve response from different files.

#### Sample SOAP request mapping
```yaml
-  request:
     method: POST
     url: /soap-simulator/services/ServiceName
     post: actionName[\s\S]*mobile.([0-9]+)
  response:
     headers:
           content-type: text/xml
     strategy: "first-found"
     files: ["stubs/<% post.1 %>/response.xml","stubs/ServiceName/actionName/default.xml"]
```
#### Sample REST request mapping
```yaml
-  request:
     method: GET
     url: /rest-simulator/services/ServiceName/actionName/([0-9]+)
  response:
     headers:
           content-type: text/xml
     strategy: "first-found"
     files: ["stubs/<% url.1 %>/response.xml","stubs/ServiceName/actionName/default.xml"]
```

### Worth to mention

- **[NIMN निम्न](https://github.com/nimndata/spec)** : Schema aware object compression. 60% and more compressed than JSON. 40% and more compressed than msgpack.
- **[अनुमार्गक (anumargak)](https://github.com/NaturalIntelligence/anumargak)** : The fastest router for node web servers.
- **[imglab](https://github.com/NaturalIntelligence/imglab)** : Web based tool to label images for object. So that they can be used to train dlib or other object detectors. You can integrate 3rd party libraries for fast labeling.
- [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser): Transform XML to JS/JSON objects, or Nimn rapidly. Transform back JSON to XML. Work in browser, node package, or CLI. Many options to customize parsing.
- [fast-lorem-ipsum](https://github.com/amitguptagwl/fast-lorem-ipsum) : Generate lorem ipsum words, sentences, paragraph very quickly.
- [Grapes](https://github.com/amitguptagwl/grapes) : Flexible Regular expression engine (for java) which can be applied on char stream. (maintainers are needed)

### Helpful articles and tutorials

- [Clean & quick way to create simulators](https://dzone.com/articles/stubby-db-clean-amp-quick-way-to-create-simulators)
- [Stubby4j to Stubmatic](https://medium.com/@amitgupta.gwl/stubby4j-to-stubmatic-a1c8b54d4758)
- [How to setup stubmatic project and stub SOAP webservices](https://naturalintelligence.github.io/Stubmatic/#exampleModal1)
- [How to delay response and stub RESTful webservices](https://naturalintelligence.github.io/Stubmatic/#exampleModal2)
- [How to route response to other servers](https://naturalintelligence.github.io/Stubmatic/#proxymodal)
- [How to make dynamic response with data sets, and expressions](https://naturalintelligence.github.io/Stubmatic/#exampleModal5)
- [How to break a response file into multiple files using dumps](https://naturalintelligence.github.io/Stubmatic/#exampleModal6)

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