xmock
Just a simple way to mock out your API calls, without running a server. Its express-like, fast and hopefully simple to use. I aim to make to 1-to-1 compatible with express 4.x, so that I can play with middleware 😄
Installation
node:
$ npm install xmock
Works with webpack and should work with browserify
// In node.js or your browser (you need to bundle) var xapp = // GET http://localhost/some/value?one=1 xapp // Keep the middleware going! xapp // And when you want to remove all your middleware xapp // still listenening, but without any middleware
Supports the usual http methods ...
- .get
- .post
- .put
- .delete
- .patch
Restoring normal http requests
-
.restore() ->
will allow normal requests to go through, but will leave your middleware intact -
.install() ->
same as xmock(), it'll capture the http requests -
.reset() ->
removes the middleware (under the hood it just resets the callback array)
Path matching
Uses express-like paths, or regexp or full path
xapp xapp // regexp with groups xapp // full paths
Middleware
Such an awesome concept, is middleware!
// So, things like arguments as middleware xapp // Catch-alls xapp // Catch-alls, but only for certain methods xapp
Credit
All of this is definitely not possible, without the great work done on these projects... faux-jax and path-to-regexp