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

monis

v0.1.1

Published

mock service for api

Downloads

12

Readme

Monis

Simple service for API mock

Quick Links

Install

npm install -g monis

⏫ go to top

Usage

monis [command] [options]

⏫ go to top

Serve

monis serve -c monis.json -p 3001

port

  • You can specify the server listening port by -p, --port.
  • Monis will use 3001 as default port.

config

  • Monis support json formated configuration & javascript which export a json configuration.
  • You can specify config file by -c, --config.
  • It will use monis.json in current working directory as default.

hot

  • You can enable hot reload mode by --hot.

⏫ go to top

Getting Start:

  1. Prepare an configuration file with json or javascript.

    // monis.json
    {
        "/fruit": {
            "get": {
                "result": [
                    {
                        "name": "apple",
                        "price": 5.3
                    },
                    {
                        "name": "melon",
                        "price": 2.5
                    }
                ],
                "count": 2,
                "@code": 500
            },
            "post": "OK"
        },
        "/meat": {
            "get": "ref#meat.json"
        }
    }
    // monis.js
    const template = {
        '/fruits': {
            'get': {
                'results|1-4': [
                    {
                        'name|1': [
                            'apple',
                            'melon',
                            'banaba',
                            'strawberry',
                            'cherry'
                        ],
                        'price|1-20.2': 1
                    }
                ],
                count: function () {
                    return this.results.length;
                },
                '@code': 400
            }
        },
        '/fruits/:fruit': {
            'get': function(params, query) {
                return {
                    name: params.fruit,
                    'price|1-20.2': 1,
                    '@code': 200
                }
            }
        },
        "/meat": {
            "get": "ref#meat.json"
        }
    };
    
    module.exports = template;
  2. Change working directory to configuration folder

    $ cd /path/to/configuration/folder
  3. Start Server

    $ monis serve

    monis will start automatically with router registered. If you try to visit localhost:3001/fruits, you can get the response:

    {
        "results": [
            {
            "name": "banaba",
            "price": 8.66
            },
            {
            "name": "melon",
            "price": 7.18
            }
        ],
        "count": 2
    }

⏫ go to top

Configuration

JSON configuration

monis configuration is like below:

{"path": { "method": response}}

There are three types of response:

  1. object

    json response is supported in configuration. you can also set the response of this request by using @code in config json.

    {
        "get": {
                "result": [
                    {
                        "name": "apple",
                        "price": 5.3
                    },
                    {
                        "name": "melon",
                        "price": 2.5
                    }
                ],
                "count": 2,
                "@code": 500
            }
    }
  2. string
    {
        "post": "OK"
    }
  3. reference

    you can set a json file as the response using ref# + relative path.

    {
        "get": "ref#meat.json"
    }

⏫ go to top

Javascript configuration

Javascript configuration can handle more complex case. And it support all the functions provided by json configuration as well.

Basic Format

Each javascript configuration should export a json object

module.exports = {
    '/fruits': {
        get: {
            result: [],
            count: 0,
        }
    }
}

Mockjs Format

Monis support mock function with Mockjs formated config.

To getting started with Mockjs, please refer to this document.

Here is an example for Mockjs styled config:

module.exports = {
    '/fruits': {
        'get': {
            'results|1-4': [
                {
                    'name|1': [
                        'apple',
                        'melon',
                        'banaba',
                        'strawberry',
                        'cherry'
                    ],
                    'price|1-20.2': 1
                }
            ],
            count: function () {
                return this.results.length;
            }
        }
    }
}

Return Code

Return Code is also supported in javascript configuration.

module.exports = {
    '/fruits': {
        get: {
            result: [],
            count: 0,
            '@code': 404
        }
    }
}

Route Parameter & URL Query

module.exports = {
    // Route Parameter
    '/fruits/:fruit': {
        'get': function(params, query) {
            return {
                name: params.fruit,
                // URL Query
                // /fruits/apple?price=2
                price: query.price || 1,
                '@code': 200
            }
        }
    }
}

⏫ go to top