Code Monkey home page Code Monkey logo

farfetched's People

Contributors

athaeryn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

farfetched's Issues

The second request to a URL throws an error

farfetched("/foo", { response: "foo" });

function text(res) { return res.text() }
function json(res) { return res.json() }

fetch("/foo").then(json).then(console.log.bind(console);
fetch("/foo").then(json).then(console.log.bind(console); // Throws TypeError: Already read

Function handlers are invoked once, response is cached

farfetched(/url/, { response: (url) => url });

fetch("url?foo=true")
  .then((r) => r.text())
  .then((text) => console.log(text))
// => "url?foo=true"

fetch("url?foo=false")
  .then((r) => r.text())
  .then((text) => console.log(text))
// => "url?foo=true"

Add ability to simulate network latency

It would be helpful to allow the simulation of network latency.

farfetched("/foo", {
  response: "bar",
  latency: 3000
});

latency could also be a function, so that the delay could be made random.

Examples in README

I think it will help a lot to include some basic examples of how to mock using this library in the README.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.