In WireMock, what does GET /__admin/requests/unmatched return during a failing test?
answer
- the 404 is not the whole story
- the server kept what it could not serve
- requests view, not the mappings view
- one admin endpoint lists them all
- WireMock findUnmatchedRequests is the static one
basics
~20 sWireMock's unmatched-requests endpoint returns every request the server received that no stub mapping served. Each one arrives as a full logged request: method, URL, headers and body. It is the first place to look when a stub-backed test unexpectedly gets a 404.
solid answer
~40 s`GET /__admin/requests/unmatched` is WireMock's list of requests that arrived and found no stub mapping to serve them. Each entry is a `LoggedRequest` — method, absolute URL, headers, cookies and body exactly as WireMock parsed them — so in a vineyard harvest-log suite you can see straight away that the client posted to `/vineyard/harvest-log` while the mapping was registered for `/vineyard/harvest-logs`. From Java there are two spellings and they are not interchangeable: the static entry point is `WireMock.findUnmatchedRequests()`, and it delegates to the instance method `findAllUnmatchedRequests()` on a configured `WireMock` client. Note that this is the *requests* view; WireMock's `GET /__admin/mappings/unmatched` is the mirror image, listing stub mappings that no request ever served. When the list tells you *that* nothing matched but not *why*, escalate to WireMock's `GET /__admin/requests/unmatched/near-misses`.
code
java · 8 linesimport static com.github.tomakehurst.wiremock.client.WireMock.*;
stubFor(get(urlPathEqualTo("/vineyard/blocks/north-slope/harvest-logs"))
.willReturn(aResponse().withStatus(200).withBody("[]")));
// the client asks for .../harvest-log (no trailing s), so the test sees 404;
// ask what actually arrived -- findUnmatchedRequests() is the STATIC form
findUnmatchedRequests().forEach(System.out::println);go deeper
Know where WireMock puts the requests it could not serve, and that they are kept rather than discarded. Be able to say that WireMock's GET /__admin/requests/unmatched is the first place to look when a stub-backed test sees a 404.
Be ready to explain what a logged request carries — method, URL, headers and body as parsed — and to name the static and instance Java calls correctly, since they differ by more than a word.
Show that you read an empty unmatched list as evidence too: it usually means the client never reached this server. Talk about confirming the port and base URL before touching a single matcher.
Own how failure output is standardised across a suite so this list appears in the report automatically, rather than every engineer re-running a failing test by hand to see what actually arrived.
## What the endpoint holds `GET /__admin/requests/unmatched` is WireMock's list of requests that reached the server and found no stub mapping willing to serve them. When that happens WireMock answers the client with a 404, but it does not throw the request away: it records it in the request journal like any other, and this endpoint is the filtered view of that journal showing only the ones nothing served. Each entry is a WireMock `LoggedRequest`. That means you get the request as WireMock actually parsed it — the method, the absolute URL including its query string, the headers, the cookies and the body — rather than what your client's own logging claims it sent. On a vineyard harvest-log suite that is usually enough on its own: you see immediately that the client called `/vineyard/harvest-log` while the mapping was registered for `/vineyard/harvest-logs`, or that it sent no `X-Vineyard-Estate` header at all. ## The two Java spellings, and why they differ This is the small trap in this corner of the API, and it catches people who learned it from autocomplete: - `WireMock.findUnmatchedRequests()` is the **static** entry point. It is what you get from a static import in a test that talks to one statically configured server. - `findAllUnmatchedRequests()` is the **instance** method on a configured `WireMock` client, and it is what the static form delegates to. The names run longer and shorter in the opposite direction from what most people guess, so it is worth committing to memory: the *shorter* name is the *static* one. In a test with a single WireMock server the static form is the ergonomic choice; the moment you run two servers in one test you hold a client per server and call the instance method on each. ## The requests view is not the mappings view Two admin paths differ by one word and answer opposite questions: | WireMock endpoint | question it answers | |---|---| | `GET /__admin/requests/unmatched` | which requests arrived that nothing served? | | `GET /__admin/mappings/unmatched` | which stub mappings has nothing ever served? | The first is a debugging tool for a failing test. The second is a hygiene tool for a stub set nobody maintains. Reaching for the wrong one is the commonest way to answer confidently while talking about something else entirely. ## When the list is not enough The unmatched list tells you *that* a request found nothing. It does not tell you which mapping was closest, or on which field the two disagreed. For that WireMock has the near-miss report at `GET /__admin/requests/unmatched/near-misses`, and in Java `WireMock.findNearMissesForAllUnmatched()`. The natural workflow is: 1. Read the unmatched list. Is the request there at all, and does it look like the request you meant to send? 2. If it is there and looks right, ask for the near-miss report and read the closest mapping's diff. 3. Fix whichever side is wrong — the client that built the URL, or the mapping that expected a different one. ## When the list is empty and the test still fails An empty unmatched list is evidence, not an absence of it. If a stub-backed test failed with a 404 and nothing appears here, the likeliest explanation is that the request never reached this WireMock server at all: - the client was pointed at the wrong port, often a hard-coded one against a dynamically assigned server; - a base URL was built before the server started and captured a placeholder; - the call went through a proxy, or to a real host that answered 404 of its own; - the test asserted against a different server instance than the one it stubbed. Confirm the port the client used against the port the server actually bound before you touch a single matcher. Diagnosing a matcher that was never consulted is the most expensive way to spend an afternoon in this part of the tooling, and the empty list is the signal that tells you to stop and check. ## Why this is the first thing to learn here Everything else in stub-server diagnosis builds on the fact that the server keeps what it could not serve. Near-miss scoring, raw traffic dumps and stub-set hygiene all assume you already know that a 404 from WireMock is the beginning of an investigation rather than the end of one, and that a single endpoint will hand you the evidence in the shape the server saw it.
- In WireMock's Java client, why does it matter whether you call findUnmatchedRequests() or findAllUnmatchedRequests()?Because in WireMock they sit at different levels. `WireMock.findUnmatchedRequests()` is the static entry point that works against the statically configured client, and it delegates to `findAllUnmatchedRequests()`, the instance method you call on a `WireMock` client object. Static-import a test against a single server and the static form is fine; run two servers in one test and you need the instance method on each client.
- The unmatched list is empty but the test still failed. Where do you look next?At whether the client reached this server at all. An empty unmatched list beside a failing test usually means the request went somewhere else — the wrong port, a proxy, or a base URL the code built before the server started. Check the port the client used against the port WireMock bound, then re-run and look again.
saying these in an interview costs you the question
- Assumes an unmatched request is discarded and cannot be inspected
- Reaches for mappings/unmatched when asked which requests nothing served
- Calls WireMock's findAllUnmatchedRequests as though it were the static entry point
- Thinks the endpoint returns near-miss scores as well as the requests
- Believes only a 500 response means a request went unmatched