Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apimocker

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apimocker

Simple HTTP server using express, for server API mocking.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
504
decreased by-8.53%
Maintainers
1
Weekly downloads
 
Created
Source

apimocker

This is a node.js module to run a simple http server, which can serve up mock service responses. Responses can be JSON or XML to simulate REST or SOAP services. Mock services are configured in the config.json file.

Installation

	sudo npm install -g apimocker

That will install globally, and allow for easier usage.

Usage

apimocker [-c, --config <path>] [-O, --output] [-p <port>]

Out of the box, you can just run "apimocker" with no arguments. Then you can visit "http://localhost:7878/first" in your browser to see it work. The output and port options can also be set in the config.json file. Values from config.json will override values from command line.

Configuration

On startup, config values are loaded from the config.json file.
During runtime, mock services can be configured on the fly. See the sample config.json file in this package. jsonMocksPath value should be an absolute path.

{
    "jsonMocksPath": "/usr/local/lib/node_modules/apimocker/samplemocks/",
    "output": true,
    "port": "7878", 
    "webServices": {
        "get": {
            "first": "king.json",
            "nested/ace": "ace.json",
            "var/:id": "queen.xml"
        },
        "post": {
            "king": "king.json"
        },
        "all": {
            "queen": "queen.xml"
        }
    }
}

The most interesting part of the configuration file is the webServices section. This contains the mock service URLs grouped by HTTP verb.
For instance, a request sent to "http://server:port/first" will return the king.json file from the samplemocks directory. Response type will match the file extension.

Runtime configuration

After starting the apimocker, mocks can be configured using a simple http api.

/admin/setMock

This allows you to set different responses for a single service at any time by sending an http request. Request can be a post containing a JSON object in the body:

{
	"verb":"get",
	"serviceUrl":"third",
	"mockFile":"queen.xml"
}

or a get with query string parameters: localhost:7878/admin/setMock?verb=get&serviceUrl=second&mockFile=ace.json

/admin/reload

If the config.json file is edited, you can send an http request to /admin/reload to pick up the changes.

FAQs

Package last updated on 08 Feb 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc