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

restful-dummy-server

v1.0.4

Published

This can be used to mock restful api responses.

Downloads

9

Readme

restful-dummy-server

This can be used to mock Rest API responses.

How to install

npm install -g restful-dummy-server

How to use

CLI options

1. port

"scripts": {
    "start": "restful-dummy-server -port 4000"
}

This will start restful dummy server on port 4000

2. host

You can also mention host.

"scripts": {
    "start": "restful-dummy-server -port 4000 -host xx.xx.xx.xx"
}

3. static

"scripts": {
    "start": "restful-dummy-server -port 4000 -static ./data"
}

static is used to know the relative path of a folder where all statics files are hosted. Which then would be used by Dummy server to download files against the rest api dowbloaded request. Here this folder is data.

4. config

"scripts": {
    "start": "restful-dummy-server -port 4000 -static ./data -config ./test"
}

config is used to know the relative path of a folder which are having dummy request response instruction files in .json extensions only.

Note -

  1. Assuming port is 4000 for all below examples.
  2. data folder is having test.png file

Example 1- test/config.json

[{
    "request": {
        "url": "/get/message",
        "method": "get"
    },
    "response": {
        "headers": {},
        "body": "Hello Dummy Server"
    }
}]

In this case if you hit http://localhost:5000/get/message then you will get Hello Dummy Server as response.

Example 2- test/config.json

[{
    "request": {
        "url": "/get/:message",
        "method": "get"
    },
    "response": {
        "headers": {},
        "body": { "message": "Hello Dummy Server" }
    }
}]

In this case if you hit http://localhost:5000/get/test or http://localhost:5000/get/msg etc. then you will get { "message": "Hello Dummy Server" } as response.

Example 3- test/config.json

[{
    "request": {
        "url": "/get/png/*.*",
        "method": "get"
    },
    "response": {
        "headers": {
            "Content-Disposition": "attachment;filename= test.png;"
        },
        "body": "./test.png"
    }
}]

In this case if you hit http://localhost:5000/get/png/abc.png or http://localhost:5000/get/png/msg.png etc. then test.png will be downloaded as response.

Example 4- test/config.json

[{
    "request": {
        "url": "/get/**/*.*",
        "method": "get"
    },
    "response": {
        "headers": {
            "Content-Disposition": "attachment;filename= test.png;"
        },
        "body": "./test.png"
    }
}]

In this case if you hit http://localhost:5000/get/png/abc.png or http://localhost:5000/get/png/png2/msg.jpeg etc. then test.png will be downloaded as response.

Example 5- test/config.json

[{
    "request": {
        "url": "/get/**/*.png",
        "method": "get"
    },
    "response": {
        "headers": {
            "Content-Disposition": "attachment;filename= test.png;"
        },
        "body": "./test.png"
    }
}]

In this case if you hit http://localhost:5000/get/png/abc.png or http://localhost:5000/get/png/png2/msg.png etc. then test.png will be downloaded as response.

Example 6- test/config.json

[{
    "request": {
        "url": "/get/**/*.png",
        "method": "get"
    },
    "response": {
        "headers": {
            "Content-Disposition": "attachment;filename= test.png;"
        },
        "body": "./test.png",
        "delay": 2000 
    }
}]

Above delay is the special attribute which would cause Dummy server to respond in 2000 milliseconds.

5. proxy

"scripts": {
    "start": "restful-dummy-server -port 4000 -static ./data -config ./test -proxy localhost:2000"
}

If proxy is provided then Dummy server will redirect the request to the proxy server if there is no matching record found.