New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

http-mockserver

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-mockserver

Testing made easy with mocked http servers

  • 1.1.5
  • Source
  • npm
  • Socket score

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

Install

$ npm install --save http-mockserver

Usage

Start mockServer

$ http-mockserver --port 3000

Connect to mockServer

const { MockClient } = require('http-mockserver');
const mockServerHost = 'localhost:3000'; // Connect to MockServer on localhost:3000
const myMockClient = new MockClient(8888, mockServerHost); // start a mockServer instance on port 8888

// Setup route on localhost:8888/rest/users
myMockClient.addRoute({
	uri: '/rest/users',
	method: 'GET',
	response: {
		users: [],
		count: 0
	}
});

CLI options

$ http-mockserver --help

  Usage
    $ http-mockserver

  Options
    --port     MockServer port, default: 3000
    --mocks    Path to mock config files

Client API

The following methods can be called on any MockClient instance

mockClient.addRoute([options])

Adds a new route to the mockServer. Returns a promise.

Options:
  • uri: uri of request, eg. /users/5345
  • method: method of request, eg. GET
  • response: Response object
    • body, eg. {data: "hello"}
    • statusCode, eg. 200
    • headers, eg. {"Content-Type": "application/json"}
mockClient.getRequests()

Returns a promise with a list of requests made to the mockServer

mockClient.clear()

Removed all mocks and requests made to the mockServer

FAQs

Package last updated on 10 Jan 2017

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