npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mockify

v0.2.3

Published

A tool to easily proxy and mock an existing API.

Downloads

4

Readme

mockify

Mockify is the API mocking made easy.

Record and replay your API calls for tests or development.

Warning: mockify is still experimental not ready for production.

Installation

  • From npm:
npm install -g mockify
  • From source:
git clone https://github.com/gandi/mockify.git && cd mockify
sudo npm link

Development

If you want to work on mockify, use Gulp tasks:

cd mockify

# install dependencies
npm install
cd www
bower install
cd ..

# in a first terminal, watch your app (lint all JS and build the webapp for each modification)
./gulp watch

# in a second one, start mockify
./gulp start

# Just type ./gulp to see all available tasks.

Open your browser at localhost:3000

How does it work?

Mockify is basicly a proxy manager, just follow those simple steps:

  1. Create a target toward the service to mock
  2. Enable it, the proxy will start
  3. Turn record mode on
  4. Make a bunch of api calls through the proxy
  5. Turn mock mode on
  6. Mockify now returns recorded requests

The proxy will record everything which passing through it and the mock will use this data to return exactly the same results, according HTTP verb, status, query parameters, etc.

Mockify uses a SQLite database to store data and spawn in-memory databases for mocking.

The different parts of mockify

{<5>}alt tag

Features

  • Save query and response of API(s)
  • Mock the exact same request with exact same results

Using mockify with the built-in webapp

{<6>}alt tag

Using mockify from the command line

You can fully use mockify only with a shell. Here a quick example.

$ mockify start
mockify daemon has been started.

$ mockify add-target 4000 http://jsonplaceholder.typicode.com
The target has been added.

┌────┬──────┬─────────────────────────────────────┬───────────┬──────────┬─────────┬─────────┐
│ Id │ Port │ Url                                 │ Recording │ Proxying │ Mocking │ Enabled │
├────┼──────┼─────────────────────────────────────┼───────────┼──────────┼─────────┼─────────┤
│ 1  │ 4000 │ http://jsonplaceholder.typicode.com │ 1         │ false    │ false   │ false   │
└────┴──────┴─────────────────────────────────────┴───────────┴──────────┴─────────┴─────────┘

$ mockify enable-target 1
[proxy-out] Proxy listening on localhost:4000 and proxying http://jsonplaceholder.typicode.com

$ mockify log
# in another shell, type: curl localhost:4000/users
localhost:4000/users -> jsonplaceholder.typicode.com/users
^C

$ mockify start-mock 1
[mock-out] Mock listening on port 4000 and mocking the target ID: 1

$ mockify log
# in another shell, type: curl localhost:4000/users
200 GET /users on localhost:4000
^C

$ mockify disable-target 1
The target has been disabled.

$ curl http://localhost:4000/users
curl: (7) Failed to connect to localhost port 4000: Connection refused

Just type mockify to list all available commands.

Using mockify module from node.js

var mockify = require('mockify');

/* All these methods return a promise: */

// start mockify daemon
mockify.start()
  .then(function () { /* ... */ })
  .catch(function () { /* ... */ });

// stop mockify daemon
mockify.stop();

// list the daemon(s) status
mockify.status();

// send a ping to mockify to check if it is running
mockify.sayHello();

// start the httpserver which serves the webapp
mockify.startHttp();

// stop the httpserver
mockify.stopHttp();

// list saved targets
mockify.listTargets();

// add a target
mockify.addTarget(port, url);

// remove a target
mockify.removeTarget(id);

// start a proxy to the url of the target
// (stop the mock if it was running)
mockify.startProxy(id);

// start a mock to the url of the target
// (stop the proxy if it was running)
mockify.startMock(id);

// disable proxy or mock of a target
mockify.disableTarget(id);

// enable / disable the recording for a target
mockify.recordingTarget(id, bool);

/* You can log all proxies / mocks output with the log method which returns an eventEmitter: */
mockify.log()
  .on('response', console.log)
  .on('out', console.info)
  .on('error_', console.error);

Roadmap

  • Customize recorded sessions (edit response and request content, status code, headers)
  • Add delay for proxy responses to test unexpected scenarios
  • Enhance webapp logs to keep track of history