GithubHelp home page GithubHelp logo

partial-api-mock's Introduction

Partial API Mocking

Partial API Mocking in Javascript for use in UX design and rapid prototyping.

This uses Sinon to partially mock the api. This lets us use our full api while mocking new endpoints or new versions of responses. This way we can drive ahead on new features and consider the JSON fixtures a contract between the UI and API.

See the mock_routes file to supply an array of url/response pairings that this module will provide. The Sinon library is going to intercept the XHR request and provide those responses. The app is never going to know that the data didn't come from your ajax provider of choice.

This project uses RequireJS.

Example

Open the mock.js file, and look inside, you'll see that we are building an array of urls. The url specifiers can be regular expressions or strings.

[
  {
    url: /\/projects\/(\d+)/,
    response: projectFixture
  }, {
    url: "/projects",
    response: projectsFixture
  }
]

In this example, both projectFixture and projectsFixture are strings with JSON responses. When the application makes a request for /projects/385, the fake server will intercept the request, and hand the fixture data back as a response. Any request not matching the urls in the mock array will continue to the API for fulfillment.

TODO

  • A full example application

partial-api-mock's People

Contributors

craig-davis avatar

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.