1.0.7 • Published 3 years ago

wah v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

Wah

Fake HTTP requests

Install

$ npm install --save wah

Usage

import Wah from "wah";

const http = new Wah({
  store: { users: [{ id: 1, username: "john" }] },
  delay: 1500
});

http.mock("GET", "users/:username", (store, request) => {
  const { username } = request.params;

  const data = store.users.find(user => user.username === username);

  if (!data) {
    throw new Error("User not found");
  }

  return data;
});

http.mock("POST", "users", (store, request) => {
  const data = {};
  data.id = store.users.length + 1;

  Object.assign(data, request.body);

  return data;
});

http
  .get("users/john")
  .then(user => console.log(user)) // { id: 1, username: "john" }
  .catch(error => console.log(error.message)); // User not found

http
  .post("users", { body: { username: "don" } })
  .then(user => console.log(user)); // { id: 2, username: "don" }
1.0.2

3 years ago

1.0.1

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.0

4 years ago