For enterprise customers the CLI offers the possibility of running your Mock APIs locally, removing the need to have a connection to the internet.

Getting Access

Contact the WireMock team to request a license file, which should be placed in the appropriate configuration location for your operating system:

  • Windows: %LOCALAPPDATA%\wiremock-cli (typically C:\Users\{username}\AppData\Local\wiremock-cli)
  • macOs: /Users/{username}/.config/wiremock-cli
  • Linux: $XDG_CONFIG_HOME/wiremock-cli (typically /home/{username}/.config/wiremock-cli)

Usage

First you will need to pull one or more of your Mock APIs locally:

wiremock pull mock-api <mock-api-id>

Multiple Mock APIs can be pulled with one command by appending multiple ids:

wiremock pull mock-api <mock-api-id> <mock-api-id> <mock-api-id>

At present you can get the Mock API Id by browsing into a Mock API at https://app.wiremock.cloud and extracting it from the URL - for instance in the URL https://app.wiremock.cloud/mock-apis/33eye3l9/stubs/1e0d7dc0-06a0-49a2-81a7-f5d6a40bfa3d, the ID is 33eye3l9.

This will create a .wiremock directory in the current working dir, and populate it with the necessary files to be able to run the identified Mock API.

You can pass a --wiremock-dir argument to override the default .wiremock directory.

Inside the .wiremock directory you will find the WireMock environment file which contains all the Mock APIs you have pulled down. This is a yaml file in the following format:

services:
  <service-id>:
    type: '<mock_api_type>'
    name: 'Mock API name'
    cloud_id: '<mock-api-id>'
    path: './mock-api-name'
    port: 8080

The type field specifies the type of the Mock API you have just pulled down. This field allows the 4 Mock API types supported by WireMock Cloud:

  • REST
  • gRPC
  • GraphQL
  • Unstructured

The port field specifies the port that the local mock api will run on.

The path field specifies the path to the Mock API directory. This is where all the files relating to the Mock API will be stored. If the Mock API contains any stubs, they will be stored in the stub-mappings.yaml file along with the OpenAPI specification if the Mock API is a REST Mock API and the GraphQL schema if the Mock API is a GraphQL Mock API.

You can pull down multiple Mock APIs at once by running the pull mock-api command multiple times.

You can then run the Mock API as so:

wiremock run

This will run all the Mock APIs you have pulled down into the .wiremock directory. A table will be printed showing you which port is being used for which API.

(Naturally you can pass the same --wiremock-dir argument to override the default .wiremock directory.)

Re-pulling Mock APIs defined in the WireMock environment file

If you have modified your Mock APIs in WireMock Cloud, you can re-pull them by running the pull mock-api command again. This will overwrite any changes you have made locally. To do this you can run the same command as before
specifying the Mock API Id:

wiremock pull mock-api <mock-api-id>

Or multiple Mock APIs can be pulled with one command by appending multiple ids:

wiremock pull mock-api <mock-api-id> <mock-api-id> <mock-api-id>

Or you can run the pull mock-api command specifying the <service-id> from your local WireMock environment file:

For example, if your WireMock environment file contains the following:

services:
  payment-mock-api:
    type: 'Unstructured'
    name: 'Payment Mock API'
    cloud_id: '23der3'
    path: './payment-mock-api'
    port: 8080

You can re-pull the Mock API by running the following command:

wiremock pull mock-api payment-mock-api

As with pulling mutliple Mock APIs, you can re-pull multiple services by appending multiple <service-id>:

wiremock pull mock-api payment-mock-api order-mock-api

If you want to re-pull all the Mock APIs you have defined in your local WireMock environment file, you can run the pull mock-api command without any mock API Id or service Id and specifying the --all flag:

wiremock pull mock-api --all

Running in a Container

The CLI is published to Docker Hub as wiremock/wiremock-cli. By default, it executes the run command, but in order for the run command to be able to operate you must mount your config directory to /etc/wiremock-cli and the working directory containing your mock APIs to /work.

You will also need to publish the appropriate ports for the services you are running.

Here is a typical example on Linux or macOs when running two Mock APIs:

docker run \
  -v ~/.config/wiremock-cli:/etc/wiremock-cli \
  -v $(pwd):/work \
  -p 8080:8080 \
  -p 8081:8081 \
  wiremock/wiremock-cli:latest