🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

node-api-mocker

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-api-mocker

Node-Api-Mocker is a node module which allow you to simulate a rest service / rest api. You can define the api as you like using a conf.json, sample can be found in `/spec/test-conf/`. You can configure a port on which the server will listen and also an f

1.0.1
latest
Source
npm
Version published
Weekly downloads
3
-91.43%
Maintainers
1
Weekly downloads
 
Created
Source

Node-Api-Mocker

npm downloads Build Status Inline docs Code Climate Test Coverage

Description

Node-Api-Mocker is a node module which allow you to simulate a rest service / rest api. You can define the api as you like using a conf.json, sample can be found in /spec/test-conf/. You can configure a port on which the server will listen and also an fail rate for request. This feature enables you to test server error which your normally should not receive. Like internal errors or similar things. Node-Api-Mocker is so designed that you can either use it via command line or require it. Which makes it an ideal tool for testing. And usages during development.

Schema for the conf.json:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "global_conf": {
            "type": "object",
            "properties": {
                "port": {
                    "type": "integer"
                },
                "failing_rate": {
                    "type": "integer"
                }
            }
        },
        "routes": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "method": {
                        "type": "string"
                    },
                    "path": {
                        "type": "string"
                    },
                    "success": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "status": {
                                    "type": "integer"
                                },
                                "body": {
                                    "type": "object"
                                }
                            },
                            "required": [
                                "status",
                                "body"
                            ]
                        }
                    },
                    "error": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "status": {
                                    "type": "integer"
                                },
                                "body": {
                                    "type": "object"
                                }
                            },
                            "required": [
                                "status",
                                "body"
                            ]
                        }
                    }
                },
                "required": [
                    "method",
                    "path",
                    "success",
                    "error"
                ]
            }
        }
    },
    "required": [
        "global_conf",
        "routes"
    ]
}

Constributor

Templum

Tech

Node-Api-Mocker is powered by the following node modules:

  • Express - Fast, unopinionated, minimalist web framework for Node.js
  • jsonschema - JSON schema validator, which is designed to be fast and simple to use. The latest IETF published draft is v4, this library is mostly v4 compatible.

Installation

Installation from git:

$ git clone https://github.com/Templum/node-api-mocker.git
$ cd node-api-mocker
$ npm install --production

Installation from npm:

$ npm install node-api-mocker
$ npm install -g node-api-mocker //Recommended when using as command line tool

Usage

Usage via require():

var apiMocker = require('node-api-mocker');
apiMocker('path/to/config/file.json', (server) => {
    // Do what ever you want with server
});

Usage via command line:

$ node-api-mocker path/to/config/file.json

Changelog

1.0.0

  • Added Schema for config.json
  • Restructured Project
  • Removed on validation solution for the conf.json
  • Errors regarding server start now don't get caught
  • Bugfixes

Development

Want to contribute? Great! Feel free to clone and set up pull request. Or send issue reports.

Todos

  • Enhance Documentation with code samples
  • Rewrite some Util Modules as class
  • Testing

Keywords

Rest

FAQs

Package last updated on 28 Oct 2016

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