A library-agnostic API mocking library.
- Hook into your application's HTTP transport to intercept requests.
- Pass a request through demock, which in turn passes it through all the configured request filters.
- Pass the filtered request down to the HTTP transport to make the actual HTTP request.
- 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.
- Pass the fitered response up to the application.
Two transport adaptors are already available:
- adaptors/jquery.js
- adaptors/angular.js
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 ..
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.
{
method: 'GET',
url: '/api/users',
params: { id: 1, sortKey: 'name' }
}
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).
{
statusCode: 200,
statusText: 'OK',
data: [{ name: 'John' }, { name: 'Jane' }]
}