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 - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0

samplemocks/xml/queen.xml

6

config.json
{
"note": "This is a sample config file.",
"jsonMocksPath": "/usr/local/lib/node_modules/apimocker/samplemocks/",
"note": "This is a sample config file. You should change the mockDirectory to a more reasonable path.",
"mockDirectory": "/usr/local/lib/node_modules/apimocker/samplemocks/",
"output": true,

@@ -17,5 +17,5 @@ "port": "7878",

"all": {
"queen": "queen.xml"
"queen": "xml/queen.xml"
}
}
}

@@ -6,3 +6,3 @@ var express = require('express'),

"port": "8888",
"jsonMocksPath": "./mocks/",
"mockDirectory": "./mocks/",
"output": false,

@@ -104,3 +104,3 @@ "webServices": {

// apiMocker.log("Returning mock: " + options.verb.toUpperCase() + " " + options.serviceUrl + " : " + options.mockFile);
res.sendfile(apiMocker.getMockPath(options), {root: apiMocker.options.jsonMocksPath});
res.sendfile(apiMocker.getMockPath(options), {root: apiMocker.options.mockDirectory});
});

@@ -107,0 +107,0 @@ };

{
"name": "apimocker",
"description": "Simple HTTP server using express, for server API mocking.",
"version": "0.0.3",
"version": "0.1.0",
"author": {

@@ -6,0 +6,0 @@ "name": "Greg Stroup",

@@ -5,2 +5,3 @@ # apimocker

Mock services are configured in the config.json file.
Using apimocker, you can develop your web or mobile app with no dependency on back end services.
(There are lots of these projects out there, but I wrote this one to support all kinds of responses,

@@ -12,11 +13,24 @@ to allow on-the-fly configuration, and to run in node.)

That will install globally, and allow for easier usage.
(On Windows, you don't need "sudo".)
## Usage
apimocker [-c, --config \<path\>] [-O, --output] [-p \<port\>]
<br/><br/>
Out of the box, you can just run "apimocker" with no arguments.
apimocker [-c, --config \<path\>] [-O, --output] [-p \<port\>]
Out of the box, you can just run "apimocker" with no arguments.
(Except on window. See below.)
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.
After you get up and running, you should put your mock responses in a better location.
It's not a good idea to keep them under the "node_modules" directory.
### Windows note
After installing from npm, you'll need to edit this file:
/Users/xxxxx/AppData/Roaming/npm/node_modules/apimocker/config.json
Change the "mockDirectory" to point to this location.
(Or another location where you put the mock responses.)
mockDirectory: /Users/xxxxx/AppData/Roaming/npm/node_modules/apimocker/samplemocks
## Configuration

@@ -26,6 +40,7 @@ On startup, config values are loaded from the config.json file.

See the sample config.json file in this package.
jsonMocksPath value should be an absolute path.
mockDirectory value should be an absolute path.
```js
{
"jsonMocksPath": "/usr/local/lib/node_modules/apimocker/samplemocks/",
"note": "This is a sample config file. You should change the mockDirectory to a more reasonable path.",
"mockDirectory": "/usr/local/lib/node_modules/apimocker/samplemocks/",
"output": true,

@@ -36,2 +51,3 @@ "port": "7878",

"first": "king.json",
"second": "king.json",
"nested/ace": "ace.json",

@@ -44,3 +60,3 @@ "var/:id": "queen.xml"

"all": {
"queen": "queen.xml"
"queen": "xml/queen.xml"
}

@@ -51,3 +67,4 @@ }

The most interesting part of the configuration file is the webServices section.
This contains the mock service URLs grouped by HTTP verb.
This contains the mock service URLs grouped by HTTP verb.
In each section, there's a key/value pair for each mock service. The key is the service URL (endpoint), the value is the mock response file name.
For instance, a request sent to "http://server:port/first" will return the king.json file from the samplemocks directory.

@@ -75,1 +92,4 @@ Response type will match the file extension.

If the config.json file is edited, you can send an http request to /admin/reload to pick up the changes.
## Acknowledgements
Big thanks to magalhas for his httpd-mock project. This gave me a great starting point.
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