2.0.0 • Published 4 years ago

lws-mock-response v2.0.0

Weekly downloads
4,522
License
MIT
Repository
github
Last release
4 years ago

view on npm npm module downloads Build Status Dependency Status js-standard-style

lws-mock-response

Middleware adding mock responses to lws.

Imagine the network is down or you're working offline, proxied requests to https://internal-service.local/api/users/1 would fail. In this case, Mock Responses can fill the gap. Mocks are defined in a module which can be reused between projects.

Trivial example - respond to a request for /rivers with some JSON. Save the following Javascript in a file named example-mocks.js.

class MockRivers {
  mocks () {
    return {
      route: '/rivers',
      responses: [
        {
          response: {
            type: 'json',
            body: [
              { name: 'Volga', drainsInto: 'Caspian Sea' },
              { name: 'Danube', drainsInto: 'Black Sea' },
              { name: 'Ural', drainsInto: 'Caspian Sea' },
              { name: 'Dnieper', drainsInto: 'Black Sea' }
            ]
          }
        }
      ]
    }
  }
}

Launch ws passing in your mocks module.

$ ws --mocks example-mocks.js
Serving at http://mbp.local:8000, http://127.0.0.1:8000, http://192.168.0.100:8000

GET your rivers.

$ curl http://127.0.0.1:8000/rivers
[
  {
    "name": "Volga",
    "drainsInto": "Caspian Sea"
  },
  {
    "name": "Danube",
    "drainsInto": "Black Sea"
  },
  {
    "name": "Ural",
    "drainsInto": "Caspian Sea"
  },
  {
    "name": "Dnieper",
    "drainsInto": "Black Sea"
  }
]

Adds the following options to lws.

--mocks file ...   One or more modules exporting Mock Responses.

See the tutorials for more information and examples about mock responses.


© 2016-20 Lloyd Brookes \75pound@gmail.com\.

2.0.0

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.6

7 years ago

0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago