# mocky-server

> HTTP mock server

Latest version **0.0.3** (published 2018-02-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install mocky-server
pnpm add mocky-server
yarn add mocky-server
bun add mocky-server
```

Provides the command `mocky`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2018-02-09 |
| First published | 2017-02-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 16.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Mark Middleton |
| Maintainers | coder36 |

## Links

- npm: https://www.npmjs.com/package/mocky-server
- npm.io page: https://npm.io/package/mocky-server

## Dependencies (5)

- [cors](https://npm.io/package/cors.md) ^2.8.4
- [express](https://npm.io/package/express.md) ^4.14.1
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [basic-auth](https://npm.io/package/basic-auth.md) ^1.1.0
- [body-parser](https://npm.io/package/body-parser.md) ^1.16.0

## Recent versions

- 0.0.3 (latest) — 2018-02-09
- 0.0.2 — 2017-02-03
- 0.0.1 — 2017-02-03

## README

# mocky-server

A HTTP based mock server.

Mocky aids testing of your applications by hosting mock responses so that your applications do not have to talk to real endpoints. 


### Installation
```
npm install mocky-server -g
```

### Command line

```
mocky -p <port> -f <init_routes.json>
```

### Example Usage

1) Startup up the mocky server

```
mocky
> mocky listening: http://0.0.0.0:7001
```

2) Setup an endpoint  
```
curl -0 -v -X POST http://localhost:7001/_mocky/route \
-H 'Content-Type: application/json' \
-d @- << EOF
{ 
  "method": "GET", 
  "path": "/hello?aa=bb",   
  "reply": {
    "status": 200, 
    "headers": {"qqqq": "wwww"},
    "json": {"hello": "world"}, 
    "delay": 0 
  } 
}
EOF
```


3) Review
```
curl http://localhost:7001/_mocky/routes

> [{"method":"GET","path":"/hello?aa=bb","reply":{"status":200,"headers":{"qqqq":"wwww"},"json":{"hello":"world"},"delay":0}}]
```

4) Call
```
curl -v http://localhost:7001/hello?aa=bb

*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 7001 (#0)
> GET /hello HTTP/1.1
> Host: localhost:7001
> User-Agent: curl/7.51.0
> Accept: */*
>
< HTTP/1.1 200 OK
< X-Powered-By: Express
< content-type: application/json
< qqqq: wwww
< Date: Thu, 02 Feb 2017 17:18:11 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
<
* Curl_http_done: called premature == 0
* Connection #0 to host localhost left intact
{"hello":"world"}

```

5) View request log

```
curl http://localhost:7001/_mocky/logs

> [{"url":"/hello","path":"/hello?aa=bb","method":"GET","body":{},"query":{"aa": "bb"}}]
```

6) Reset

Remove all routes and logs:

```
curl http://localhost:7001/_mocky/reset
```


# Ruby Adapter
```
require './mocky'

Mocky::start
Mocky::reset

Mocky.route({
    method: :GET, path: "/hello",
    reply: {
      json: {hello: "world"},
    }
})

puts RestClient.get 'http://localhost:7001/hello'
puts Mocky.logs

Mocky::stop
```
```
mocky listening: http://0.0.0.0:7001
{"hello":"world"}
[{"url":"/hello","path":"/hello","method":"GET","body":{},"query":{}}]
```

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