# breaking

> helper suit, for create and mock rest api, test api

Latest version **0.1.2** (published 2014-09-02) · ISC license · 0 weekly downloads

## Install

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

## 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.1.2 |
| Published | 2014-09-02 |
| First published | 2014-08-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+11 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Luo Tao |
| Maintainers | lot |
| Keywords | api, mock |

## Links

- npm: https://www.npmjs.com/package/breaking
- Repository: https://github.com/lotreal/breaking
- Issues: https://github.com/lotreal/breaking/issues
- npm.io page: https://npm.io/package/breaking

## Dependencies (3)

- [qs](https://npm.io/package/qs.md) ^2.1.0
- [debug](https://npm.io/package/debug.md) ^1.0.4
- [lodash](https://npm.io/package/lodash.md) ^2.4.1

## 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
- [@crvouga/mockingbird-service-meta](https://npm.io/package/@crvouga/mockingbird-service-meta.md) — 0 weekly downloads
- [@crvouga/mockingbird-service-hermes](https://npm.io/package/@crvouga/mockingbird-service-hermes.md) — 0 weekly downloads
- [sinon-typed-stub](https://npm.io/package/sinon-typed-stub.md) — 0 weekly downloads

## Recent versions

- 0.1.2 (latest) — 2014-09-02
- 0.1.1 — 2014-09-01
- 0.1.0 — 2014-08-29
- 0.0.9 — 2014-08-28
- 0.0.8 — 2014-08-27
- 0.0.7 — 2014-08-26
- 0.0.6 — 2014-08-22
- 0.0.5 — 2014-08-22
- 0.0.4 — 2014-08-21
- 0.0.3 — 2014-08-21
- 0.0.2 — 2014-08-21
- 0.0.1 — 2014-08-21

## README

breaking
========

nodejs helper suit, for create and mock rest api, test api


## Installation

Using [`npm`](http://npmjs.org/):

```bash
npm i --save breaking
```

## Usage

1. **breaking.bad** Create REST API server very fast.
2. **breaking.request** Verify A REST API server.

## breaking.bad

### Describe Your APIs

Here's an example: (save as 'discovery.coffee')

```coffee
module.exports =
    basePath: 'http://127.0.0.1:3010/api'
    apis: [
        {
            name: 'login'
            path: '/users/login'
            httpMethod: 'POST'
            data:
                username: 'lotreal@gmail.com'
                password: 'dev'
            response:
                '?id': 'nq41UtaBL2F79'
                token: 'kHJsOH3GZCOqPnsP0rsT4yqLB5mXH'
                ttl: 999
                created: '20140822 12:05:46'
                uid: 1
            errorResponses: []
        }

        {
            name: 'homepage'
            path: '/homepage'
            httpMethod: 'GET'
            query:
                page: 1
            response: [
                {
                    tid: 1
                    subject: 'Face Me'
                    message: 'I am content.'
                    forum:
                        fid: 2
                        name: 'news'
                        fup: 0
                }
            ]
            errorResponses: []
        }
    ]
```

### Boot the Mock API Server

```coffee
express = require 'express'
breaking = require 'breaking'
resource = require './discovery'

app = express()

breaking.bad app, resource

app.listen 3400
console.log 'breaking.bad listen to 3400...'
```

### Done!

```bash
% coffee app.coffee
breaking.bad listen to 3400...

% curl -X GET http://127.0.0.1:3400/api/homepage
[{"tid":1,"subject":"Face Me","message":"I am content.","forum":{"fid":2,"name":"news","fup":0}}]

% curl -X POST http://127.0.0.1:3400/api/users/login
{"?id":"nq41UtaBL2F79","token":"kHJsOH3GZCOqPnsP0rsT4yqLB5mXH","ttl":999,"created":"20140822 12:05:46","uid":1}%
```

## breaking.request

see: test/login.test.coffee

```coffee
breaking = require 'breaking'
api = breaking.request require './discovery'

api.login.request (err, token)->
    expect(api.login.verify token).to.be.ok
```

This code do it:

1. POST 'http://127.0.0.1:3010/api/user/login'

2. check the response is **patternEqual** as descibed by 'discovery.coffee'

### patternEqual

when request login api, server return:

- {"id":"nq41UtaBL2F79","token":"kHJsOH3GZCOqPnsP0rsT4yqLB5mXH","ttl":999,"created":"20140822 12:05:46","uid":1} : PASS

- {"token":"kHJsOH3GZCOqPnsP0rsT4yqLB5mXH","ttl":999,"created":"20140822 12:05:46","uid":1} : PASS (?id set id is optional in response)

- {"id": 5, "token":"kHJsOH3GZCOqPnsP0rsT4yqLB5mXH","ttl":999,"created":"20140822 12:05:46","uid":1} : FAIL (id shounld be a string, but return a number)

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