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

wiremock-rest-client

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wiremock-rest-client

Lightweight REST client to interact with a running WireMock server

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
decreased by-13.01%
Maintainers
1
Weekly downloads
 
Created
Source

WireMock REST Client

Description

WireMock REST client is a lightweight client to interact with a running WireMock server based on the OpenAPI 3.0 spec.

Installation

npm install wiremock-rest-client

Usage

The WireMockRestClient has 5 services which correspond with request paths as specified in the OpenAPI spec.

  • global - Global operations
  • mappings - Operations on stub mappings
  • recordings - Stub mapping record and snapshot functions
  • requests - Logged requests and responses received
  • scenarios - Scenarios support modeling of stateful behaviour

Each service contain methods to perform operations on WireMock endpoints.

Example:

import { WireMockRestClient } from 'wiremock-rest-client';

const wireMock = new WireMockRestClient('http://localhost:8080');

const stubMappings = await wireMock.mappings.getAllMappings();

console.log(stubMappings);

const stubMapping = {
    "request": {
        "method": "GET",
        "urlPathPattern": "/api/helloworld"
    },
    "response": {
        "status": 200,
        "jsonBody": {"hello": "world"},
        "headers": {
            "Content-Type": "application/json"
        }
    }
};

const response = await wireMock.mappings.createMapping(stubMapping);

console.log(response);

// Create mapping from current working directory
await wireMock.mappings.createMappingFromFile('stubs/hello-world.json');

// Create mappings from a directory recursively (based on current working directory)
await wireMock.mappings.createMappingsFromDir('stubs');

await wireMock.mappings.resetAllMappings();

const requests = await wireMock.requests.getAllRequests();

console.log(requests);

await wireMock.global.shutdown();

Logging

  • Logging is based on log4js
  • Default log level is info
  • Each log line contains a unique id to trace logs for a single request

To configure a different log level, first install log4js in your project. Configuration can be set as follows.

import log4js from 'log4js';

const logger log4js.getLogger('wiremock-rest-client');

logger.level = 'debug';

Debug level will log the request body for each request.

Example:

[2019-11-01T15:57:11.285] [INFO] wiremock-rest-client - [c47e4ee8-6e24-43a8-8fe0-bb0c60c847b7] Request: [POST] http://localhost:8080/__admin/mappings
[2019-11-01T15:57:11.285] [DEBUG] wiremock-rest-client - [c47e4ee8-6e24-43a8-8fe0-bb0c60c847b7] Request body: {"request":{"method":"GET","urlPathPattern":"/api/helloworld"},"response":{"status":200,"jsonBody":{"hello":"world"},"headers":{"Content-Type":"application/json"}}}
[2019-11-01T15:57:11.301] [INFO] wiremock-rest-client - [c47e4ee8-6e24-43a8-8fe0-bb0c60c847b7] Response: [201] Created
[2019-11-01T15:57:11.292] [INFO] wiremock-rest-client - [c3690603-c055-4412-a5b0-497704c09dd0] Request: [POST] http://localhost:8080/__admin/shutdown
[2019-11-01T15:57:11.299] [INFO] wiremock-rest-client - [c3690603-c055-4412-a5b0-497704c09dd0] Response: [200] OK

FAQs

Package last updated on 01 Nov 2019

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