Skip to content

WireMock Setup and Basic Stubbing

Running a WireMock Server

While you can run WireMock natively, and there is even an npx wiremock distribution, you must have the appropriate version of the Java Runtime installed. I prefer to use the WireMock docker container.

Video Walkhtrough

yml
services:
  wiremock:
    image: "wiremock/wiremock:3.10.0"
    container_name: my_wiremock
    ports:
      - "8443:8443"
      - "8080:8080"
    volumes:
      - ./mocks/__files:/home/wiremock/__files
      - ./mocks/mappings:/home/wiremock/mappings
    entrypoint: [ "/docker-entrypoint.sh",  "--disable-gzip", "--https-port=8443", "http-port=8080", "--record-mappings", "--enable-stub-cors", "--verbose" ]

See WireMock Docs - Docker and WireMock Standalone for details.

json
{
    "request": {
        "method":  "GET",
        "url": "/some/thing"
    },
    "response":  {
        "status": 200,
        "body": "Hello, Codemash!  It's a beautiful day!",
        "headers": {
            "Content-Type": "text/plain"
        }
    }
}
http
### Link to the Admin Response
GET http://localhost:8080/__admin

### See The Mappings
GET http://localhost:8080/__admin/mappings

### Reset  (reload mappings, files, etc.)
POST http://localhost:8080/__admin/reset

### Requests  (See the requests that have been  received - useful for debugging)
GET http://localhost:8080/__admin/requests