npm.io
1.0.36 • Published 7 years ago

wiremock-client

Licence
MIT
Version
1.0.36
Deps
1
Size
100 kB
Vulns
24
Weekly
0

WireMock Client

npm version Build Status Coverage Status Maintainability

A node client for interfacing with WireMock's admin API

WARNING: THIS LIBRARY CURRENTLY EXPERIMENTAL AND IN A PRE-ALPHA STATE

Node Example

const {Builders, Matchers, connect} = require('wiremock-client')

const mock = connect('localhost', 8080)
mock.register(Builders.post(Matchers.urlPathMatching('/api/example'))
  .withRequestBody(Matchers.containsPattern('token=auth'))
  .willReturn(Builders.aResponse()
    .withStatus(200)
    .withHeader('Content-Type', Matchers.equalTo('application/json'))
    .withBody({test: true})
  )
)

Browser Example

<script src="wiremock-client.js"></script>
const Builders =  WireMock.Builders
const Matchers =  WireMock.Matchers

const mock = WireMock.connect('localhost', 8080)
mock.register(Builders.post(Matchers.urlPathMatching('/api/example'))
  .withRequestBody(Matchers.containsPattern('token=auth'))
  .willReturn(Builders.aResponse()
    .withStatus(200)
    .withHeader('Content-Type', Matchers.equalTo('application/json'))
    .withBody({test: true})
  )
)

Features

Matchers
Url Matchers

These matchers are used for matching request urls

Url Matching
urlMatching (url)

urlPattern (pattern)


urlPathMatching (path)


urlPathPattern (pattern)

Global Matchers

containsPattern(pattern) equalTo(value)

Mappings

Stub mappings

Get all stub mapping

wireMock.getStubMapping(uuid) 

Create new stub mapping

wireMock.register(mappingBuilder|mapping)

Delete all mapping

wireMock.removeMappings()

Delete all mapping

wireMock.removeMappings()

Reset stub mappings


Get a single stub mapping


Delete a stub mapping


Save all persistent stub mappings to the backing store


Find stubs by matching on their metadata


Remove stubs by matching on their metadata


Requests
Recordings
scenarios
Near Misses
Settings
Shutdown