Giter VIP home page Giter VIP logo

demock's Introduction

demock

Build Status

A library-agnostic API mocking library.

How it works

  1. Hook into your application's HTTP transport to intercept requests.
  2. Pass a request through demock, which in turn passes it through all the configured request filters.
  3. Pass the filtered request down to the HTTP transport to make the actual HTTP request.
  4. On receiving the response, pass the response along with the original request through demock, which in turn passes it through all the configured response filters.
  5. Pass the fitered response up to the application.

Two transport adaptors are already available:

  • adaptors/jquery.js
  • adaptors/angular.js

Examples

cd examples
bower install

Then serve the parent directory from a static web server. The serve NPM module is handy:

npm install -g serve
serve ..

API

Properties

.filterPrefix

.config

.requestFilters

.responseFilters

Methods

.filterRequest(request)

.filterResponse(request, response)

Objects

request

An HTTP request. Has the following properties:

method
The request method (uppercase): GET, POST, PUT, DELETE, etc.
url
The request URL.
params
The request parameters. This is an object with key/value pairs as properties.
Example
{
    method: 'GET',
    url: '/api/users',
    params: { id: 1, sortKey: 'name' }
}

response

An HTTP response. Has the following properties:

statusCode
The response status code: 200, 404, etc.
statusText
The response status text: 'OK', 'Not Found', etc.
data
The response payload (Array/Object).
Example
{
    statusCode: 200,
    statusText: 'OK',
    data: [{ name: 'John' }, { name: 'Jane' }]
}

demock's People

Contributors

atesgoral avatar

Watchers

Nael El Shawwa 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.