Troubleshooting Matching
When an expectation does not match a request, MockServer returns a 404 response. This page explains how to diagnose and fix matching issues.
Debugging Checklist
Follow these steps in order when a request is not matching:
1. Is the expectation active?
Expectations expire after their configured times limit or timeToLive. Retrieve active expectations to confirm yours is still present:
Expectation[] active = mockServerClient.retrieveActiveExpectations(null);var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.retrieveActiveExpectations()
.then(
function (activeExpectations) {
console.log(JSON.stringify(activeExpectations));
},
function (error) {
console.log(error);
}
);from mockserver import MockServerClient
client = MockServerClient("localhost", 1080)
active = client.retrieve_active_expectations()require 'mockserver-client'
client = MockServer::Client.new('localhost', 1080)
active = client.retrieve_active_expectationsimport mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go/v7"
client := mockserver.New("localhost", 1080)
active, err := client.RetrieveActiveExpectations(nil)
if err != nil {
log.Fatal(err)
}using MockServer.Client;
using var client = new MockServerClient("localhost", 1080);
var active = client.RetrieveActiveExpectations();use mockserver_client::ClientBuilder;
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
let active = client.retrieve_active_expectations(None).unwrap();use MockServer\MockServerClient;
$client = new MockServerClient('localhost', 1080);
$active = $client->retrieveActiveExpectations();curl -X PUT "http://localhost:1080/mockserver/retrieve?type=ACTIVE_EXPECTATIONS"2. Did the request arrive at MockServer?
Verify that MockServer received the request:
HttpRequest[] requests = mockServerClient.retrieveRecordedRequests(null);var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.retrieveRecordedRequests()
.then(
function (recordedRequests) {
console.log(JSON.stringify(recordedRequests));
},
function (error) {
console.log(error);
}
);from mockserver import MockServerClient
client = MockServerClient("localhost", 1080)
requests = client.retrieve_recorded_requests()require 'mockserver-client'
client = MockServer::Client.new('localhost', 1080)
requests = client.retrieve_recorded_requestsimport mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go/v7"
client := mockserver.New("localhost", 1080)
requests, err := client.RetrieveRecordedRequests(nil)
if err != nil {
log.Fatal(err)
}using MockServer.Client;
using var client = new MockServerClient("localhost", 1080);
var requests = client.RetrieveRecordedRequests();use mockserver_client::ClientBuilder;
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
let requests = client.retrieve_recorded_requests(None).unwrap();use MockServer\MockServerClient;
$client = new MockServerClient('localhost', 1080);
$requests = $client->retrieveRecordedRequests();curl -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS"3. Check the match failure reason
MockServer logs an EXPECTATION_NOT_MATCHED event for every expectation that was compared. Each event includes a because section explaining which fields matched and which did not:
curl -X PUT "http://localhost:1080/mockserver/retrieve?type=LOGS"
In the dashboard UI, look for log entries with the pink/rose colour. Click the ... to expand the "because" section, which shows each field result colour-coded green (matched) or red (didn't match).
4. Enable full match diagnostics
By default, MockServer stops comparing fields at the first mismatch (matchersFailFast=true). To see all mismatching fields at once, disable fail-fast:
ConfigurationProperties.matchersFailFast(false);
# System property
-Dmockserver.matchersFailFast=false
# Environment variable
MOCKSERVER_MATCHERS_FAIL_FAST=false
This shows every field that does not match in a single log entry, making it much easier to identify all issues at once rather than fixing them one at a time.
5. Look for the closest match
When no expectation matches, MockServer logs a closest match summary showing which expectation was most similar to the request and how many fields matched (e.g., "matched 14/16 fields"). This immediately tells you which expectation to investigate.
Common Pitfalls
These are the most frequent reasons expectations fail to match:
Trailing slash in path
A path of /api/users does not match /api/users/. Ensure your expectation path matches exactly, or use a regex:
// Exact match - will NOT match "/api/users/"
.withPath("/api/users")
// Match with or without trailing slash
.withPath("/api/users/?")
MockServer will show a HINT in the match failure when it detects a trailing slash mismatch.
Content-Type charset mismatch
Many HTTP clients send Content-Type: application/json; charset=utf-8 but expectations often specify just application/json. This is a header value mismatch.
Solutions:
- Include the charset in your expectation:
.withHeader("Content-Type", "application/json; charset=utf-8") - Use a substring header matcher
- Omit the Content-Type header from your expectation (unspecified headers match anything)
MockServer will show a HINT when it detects this pattern.
JSON body matching semantics
By default, JSON body matching uses ONLY_MATCHING_FIELDS mode:
- Extra fields in the request body are ignored (the expectation is a subset match)
- Missing fields (a field specified in the matcher but absent from the request body) cause a failure
- Array order does not matter
- Extra array items are ignored
If you need an exact match, use STRICT mode:
// Subset match (default) - extra fields OK
.withBody(json("{\"name\": \"foo\"}", MatchType.ONLY_MATCHING_FIELDS))
// Strict match - no extra fields allowed
.withBody(json("{\"name\": \"foo\"}", MatchType.STRICT))
Regex metacharacters in paths
Paths are matched as regular expressions. Characters like ., *, +, ?, (, ), [, { have special meaning in regex.
For example, /api/v1.0/users will also match /api/v1X0/users because . matches any character. Use \. for a literal dot:
// This matches "/api/v1X0/users" too
.withPath("/api/v1.0/users")
// This only matches "/api/v1.0/users"
.withPath("/api/v1\\.0/users")
MockServer will show a HINT when it detects unescaped dots in paths.
Header name case sensitivity
HTTP header names are matched case-insensitively (per HTTP spec), but header values are case-sensitive. For example:
// Header name "content-type" matches "Content-Type" - OK
// Header value "Application/JSON" does NOT match "application/json"
.withHeader("Content-Type", "application/json")
Query parameter encoding
Query parameters are decoded before matching. ?name=hello%20world is matched against the decoded value hello world:
// Matches ?name=hello%20world and ?name=hello+world
.withQueryStringParameter("name", "hello world")
Body type confusion
Using the wrong body matcher type is a common mistake:
// This is an EXACT string match - entire body must match this text exactly
.withBody("{\"name\": \"foo\"}")
// This is a JSON subset match - only specified fields must be present
.withBody(json("{\"name\": \"foo\"}"))
// This is a regex match
.withBody(regex(".*foo.*"))
If your JSON body isn't matching, check that you are using json() and not a plain string body matcher.
Reading the "because" Output
When a request does not match an expectation, the log entry includes a "because" section. Here is an annotated example:
method matched ← GET matched GET
path didn't match: ← path comparison failed
string or regex match failed ← the matcher type used
expected: /api/users ← what the expectation specified
found: /api/user ← what was in the request
HINT: trailing slash mismatch ... ← actionable suggestion (when applicable)
body matched ← body was not checked (no body matcher)
headers matched ← all expected headers were found
cookies matched ← all expected cookies were found
Fields are listed in matching order. When matchersFailFast=true (default), only fields up to and including the first failure are shown. Set matchersFailFast=false to see all fields.
Debugging Configuration Properties
| Property | Default | Description |
|---|---|---|
matchersFailFast |
true |
When true, matching stops at the first non-matching field. Set to false to see all mismatching fields in a single log entry. |
detailedMatchFailures |
true |
When true, match failure log entries include detailed explanations of why each field did not match (expected vs actual values). |
logLevel |
INFO |
At INFO (default), all match results are logged with full detail. Set to TRACE for internal matcher-level diagnostics — see Debugging Issues → Logging Levels for how to set the log level and what each level reports. |
For full configuration details, see the Configuration page.
Programmatic Mismatch Debugging
MockServer provides a dedicated PUT /mockserver/debugMismatch endpoint that analyzes why a request does not match any active expectations. It returns structured JSON showing per-expectation, per-field match results — including the closest match.
String result = mockServerClient.debugMismatch(
request()
.withMethod("GET")
.withPath("/api/users")
.withHeader("Content-Type", "application/json")
);
System.out.println(result);// debugMismatch has no typed method in the Node client - call the REST endpoint
const response = await fetch("http://localhost:1080/mockserver/debugMismatch", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"method": "GET",
"path": "/api/users",
"headers": { "Content-Type": ["application/json"] }
})
});
console.log(await response.text());import requests
# debugMismatch has no typed method - call the REST endpoint directly
response = requests.put(
"http://localhost:1080/mockserver/debugMismatch",
json={
"method": "GET",
"path": "/api/users",
"headers": {"Content-Type": ["application/json"]},
},
)
print(response.text)require 'net/http'
require 'json'
# debugMismatch has no typed method - call the REST endpoint directly
uri = URI('http://localhost:1080/mockserver/debugMismatch')
req = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
req.body = JSON.generate(
method: 'GET',
path: '/api/users',
headers: { 'Content-Type' => ['application/json'] }
)
response = Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
puts response.bodyimport (
"net/http"
"strings"
)
// debugMismatch has no typed method - call the REST endpoint directly
body := `{"method":"GET","path":"/api/users","headers":{"Content-Type":["application/json"]}}`
req, _ := http.NewRequest("PUT", "http://localhost:1080/mockserver/debugMismatch", strings.NewReader(body))
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()using System.Net.Http;
using System.Text;
// debugMismatch has no typed method - call the REST endpoint directly
using var http = new HttpClient();
var body = new StringContent(
"{\"method\":\"GET\",\"path\":\"/api/users\",\"headers\":{\"Content-Type\":[\"application/json\"]}}",
Encoding.UTF8, "application/json");
var response = await http.PutAsync("http://localhost:1080/mockserver/debugMismatch", body);
Console.WriteLine(await response.Content.ReadAsStringAsync());use reqwest::blocking::Client;
// debugMismatch has no typed method - call the REST endpoint directly
let analysis = Client::new()
.put("http://localhost:1080/mockserver/debugMismatch")
.header("Content-Type", "application/json")
.body(r#"{"method":"GET","path":"/api/users","headers":{"Content-Type":["application/json"]}}"#)
.send()
.unwrap()
.text()
.unwrap();
println!("{}", analysis);use GuzzleHttp\Client;
// debugMismatch has no typed method - call the REST endpoint directly
$http = new Client();
$response = $http->put('http://localhost:1080/mockserver/debugMismatch', [
'json' => [
'method' => 'GET',
'path' => '/api/users',
'headers' => ['Content-Type' => ['application/json']],
],
]);
echo (string) $response->getBody();curl -X PUT "http://localhost:1080/mockserver/debugMismatch" \
-H "Content-Type: application/json" \
-d '{
"method": "GET",
"path": "/api/users",
"headers": {
"Content-Type": ["application/json"]
}
}' Response Format
The response is a JSON object with:
totalExpectations— the number of active expectations comparedclosestMatch— which expectation had the fewest differencesresults— per-expectation match analysis with field-level differences
{
"totalExpectations": 2,
"closestMatch": {
"expectationId": "abc-123",
"matchedFields": 14,
"totalFields": 16
},
"results": [
{
"expectationId": "abc-123",
"expectationPath": "/api/users",
"expectationMethod": "POST",
"matches": false,
"matchedFieldCount": 14,
"totalFieldCount": 16,
"differences": {
"method": [
"string or regex match failed expected: POST found: GET"
]
}
}
]
}
Worked Example: "My test is getting 404"
When your test receives a 404, use the debug endpoint to find out exactly why:
// 1. Set up your expectation
mockServerClient.when(
request().withMethod("POST").withPath("/api/users")
.withBody(json("{\"name\": \"foo\"}"))
).respond(response().withStatusCode(201));
// 2. Your test sends a request that gets 404 - why?
// 3. Debug the mismatch
String analysis = mockServerClient.debugMismatch(
request()
.withMethod("GET") // oops - wrong method!
.withPath("/api/users")
.withBody("{\"name\": \"foo\"}")
);
// The response will show:
// - method didn't match: expected POST, found GET
// - matchedFieldCount: 15/16 (all fields matched except method)var mockServerClient = require('mockserver-client').mockServerClient;
var client = mockServerClient("localhost", 1080);
// 1. Set up your expectation
await client.mockAnyResponse({
"httpRequest": {
"method": "POST",
"path": "/api/users",
"body": { "type": "JSON", "json": { "name": "foo" } }
},
"httpResponse": { "statusCode": 201 }
});
// 2. Your test sends a request that gets 404 - why?
// 3. Debug the mismatch (no typed method - call the REST endpoint)
const response = await fetch("http://localhost:1080/mockserver/debugMismatch", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"method": "GET", // oops - wrong method!
"path": "/api/users",
"body": "{\"name\": \"foo\"}"
})
});
console.log(await response.text());import requests
from mockserver import MockServerClient, HttpRequest, HttpResponse
client = MockServerClient("localhost", 1080)
# 1. Set up your expectation
client.when(
HttpRequest(method="POST", path="/api/users", body={"name": "foo"})
).respond(
HttpResponse(status_code=201)
)
# 2. Your test sends a request that gets 404 - why?
# 3. Debug the mismatch (no typed method - call the REST endpoint)
response = requests.put(
"http://localhost:1080/mockserver/debugMismatch",
json={
"method": "GET", # oops - wrong method!
"path": "/api/users",
"body": '{"name": "foo"}',
},
)
print(response.text)require 'mockserver-client'
require 'net/http'
require 'json'
include MockServer
client = MockServer::Client.new('localhost', 1080)
# 1. Set up your expectation
client.when(
HttpRequest.new(method: 'POST', path: '/api/users', body: Body.json('{"name": "foo"}'))
).respond(
HttpResponse.new(status_code: 201)
)
# 2. Your test sends a request that gets 404 - why?
# 3. Debug the mismatch (no typed method - call the REST endpoint)
uri = URI('http://localhost:1080/mockserver/debugMismatch')
req = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
req.body = JSON.generate(method: 'GET', path: '/api/users', body: '{"name": "foo"}')
response = Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
puts response.bodyimport (
"net/http"
"strings"
mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go/v7"
)
client := mockserver.New("localhost", 1080)
// 1. Set up your expectation
client.When(
mockserver.Request().Method("POST").Path("/api/users").JSONBody(`{"name":"foo"}`),
).Respond(
mockserver.Response().StatusCode(201),
)
// 2. Your test sends a request that gets 404 - why?
// 3. Debug the mismatch (no typed method - call the REST endpoint)
body := `{"method":"GET","path":"/api/users","body":"{\"name\": \"foo\"}"}`
req, _ := http.NewRequest("PUT", "http://localhost:1080/mockserver/debugMismatch", strings.NewReader(body))
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()using System.Net.Http;
using System.Text;
using MockServer.Client;
using MockServer.Client.Models;
using var client = new MockServerClient("localhost", 1080);
// 1. Set up your expectation
client.When(
HttpRequest.Request().WithMethod("POST").WithPath("/api/users").WithJsonBody("{\"name\": \"foo\"}")
).Respond(
HttpResponse.Response().WithStatusCode(201)
);
// 2. Your test sends a request that gets 404 - why?
// 3. Debug the mismatch (no typed method - call the REST endpoint)
using var http = new HttpClient();
var debugBody = new StringContent(
"{\"method\":\"GET\",\"path\":\"/api/users\",\"body\":\"{\\\"name\\\": \\\"foo\\\"}\"}",
Encoding.UTF8, "application/json");
var response = await http.PutAsync("http://localhost:1080/mockserver/debugMismatch", debugBody);
Console.WriteLine(await response.Content.ReadAsStringAsync());use mockserver_client::{ClientBuilder, HttpRequest, HttpResponse};
use reqwest::blocking::Client;
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
// 1. Set up your expectation
client.when(
HttpRequest::new().method("POST").path("/api/users").json_body(serde_json::json!({"name": "foo"}))
).respond(
HttpResponse::new().status_code(201)
).unwrap();
// 2. Your test sends a request that gets 404 - why?
// 3. Debug the mismatch (no typed method - call the REST endpoint)
let analysis = Client::new()
.put("http://localhost:1080/mockserver/debugMismatch")
.header("Content-Type", "application/json")
.body(r#"{"method":"GET","path":"/api/users","body":"{\"name\": \"foo\"}"}"#)
.send()
.unwrap()
.text()
.unwrap();
println!("{}", analysis);use MockServer\MockServerClient;
use MockServer\HttpRequest;
use MockServer\HttpResponse;
use GuzzleHttp\Client;
$client = new MockServerClient('localhost', 1080);
// 1. Set up your expectation
$client->when(
HttpRequest::request()->method('POST')->path('/api/users')->jsonBody(['name' => 'foo'])
)->respond(
HttpResponse::response()->statusCode(201)
);
// 2. Your test sends a request that gets 404 - why?
// 3. Debug the mismatch (no typed method - call the REST endpoint)
$http = new Client();
$response = $http->put('http://localhost:1080/mockserver/debugMismatch', [
'json' => ['method' => 'GET', 'path' => '/api/users', 'body' => '{"name": "foo"}'],
]);
echo (string) $response->getBody();# 1. Set up your expectation
curl -v -X PUT "http://localhost:1080/mockserver/expectation" -d '{
"httpRequest": {
"method": "POST",
"path": "/api/users",
"body": { "type": "JSON", "json": { "name": "foo" } }
},
"httpResponse": { "statusCode": 201 }
}'
# 2. Debug why a GET request does not match
curl -X PUT "http://localhost:1080/mockserver/debugMismatch" -d '{
"method": "GET",
"path": "/api/users",
"body": "{\"name\": \"foo\"}"
}' This endpoint is also available via the MCP debug_request_mismatch tool for AI-assisted debugging.
Retrieving Logs by Correlation ID
Every incoming HTTP request is assigned a unique correlation ID. All log entries for that request's lifecycle (received, match attempts, response) share this ID. This is invaluable when debugging a specific request among many — you can isolate exactly what happened.
Finding the Correlation ID
The correlation ID appears in:
- Dashboard UI — as a small chip on grouped log entries (click to copy)
- Log text — in the prefix of each log message
- Typed log entries — as the
correlationIdfield when usingformat=LOG_ENTRIES
Retrieving by Correlation ID
Once you have a correlation ID, retrieve all log entries for that request:
String logs = mockServerClient.retrieveLogsByCorrelationId("abc-123-def-456");// no typed correlationId filter - call the REST endpoint
const response = await fetch(
"http://localhost:1080/mockserver/retrieve?type=LOGS&correlationId=abc-123-def-456",
{ method: "PUT" }
);
console.log(await response.text());import requests
# no typed correlationId filter - call the REST endpoint
response = requests.put(
"http://localhost:1080/mockserver/retrieve",
params={"type": "LOGS", "correlationId": "abc-123-def-456"},
)
print(response.text)require 'net/http'
# no typed correlationId filter - call the REST endpoint
uri = URI('http://localhost:1080/mockserver/retrieve?type=LOGS&correlationId=abc-123-def-456')
response = Net::HTTP.start(uri.host, uri.port) { |http| http.request(Net::HTTP::Put.new(uri)) }
puts response.bodyimport "net/http"
// no typed correlationId filter - call the REST endpoint
url := "http://localhost:1080/mockserver/retrieve?type=LOGS&correlationId=abc-123-def-456"
req, _ := http.NewRequest("PUT", url, nil)
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()using System.Net.Http;
// no typed correlationId filter - call the REST endpoint
using var http = new HttpClient();
var response = await http.PutAsync(
"http://localhost:1080/mockserver/retrieve?type=LOGS&correlationId=abc-123-def-456", null);
Console.WriteLine(await response.Content.ReadAsStringAsync());use reqwest::blocking::Client;
// no typed correlationId filter - call the REST endpoint
let logs = Client::new()
.put("http://localhost:1080/mockserver/retrieve?type=LOGS&correlationId=abc-123-def-456")
.send()
.unwrap()
.text()
.unwrap();
println!("{}", logs);use GuzzleHttp\Client;
// no typed correlationId filter - call the REST endpoint
$http = new Client();
$response = $http->put('http://localhost:1080/mockserver/retrieve', [
'query' => ['type' => 'LOGS', 'correlationId' => 'abc-123-def-456'],
]);
echo (string) $response->getBody();curl -X PUT "http://localhost:1080/mockserver/retrieve?type=LOGS&correlationId=abc-123-def-456"The correlation ID is visible in the dashboard UI as a small chip on grouped log entries. Click it to copy the ID.
Typed Log Entry Retrieval
Instead of retrieving logs as plain text, you can retrieve structured LogEntry objects. This is useful for programmatic analysis — filtering by type, inspecting expectations, or building custom reports:
LogEntry[] entries = mockServerClient.retrieveLogEntries(null);
LogEntry[] matchEntries = mockServerClient.retrieveLogEntries(
request().withPath("/api/users")
);
// Deserialized entries include: type, logLevel, correlationId, epochTime,
// timestamp, port, expectationId, messageFormat, arguments, because.
// Note: httpRequest, httpResponse, expectation, throwable are in the JSON
// but not deserialized (returned as null on the client).
for (LogEntry entry : entries) {
System.out.println(entry.getType() + " at " + entry.getTimestamp());
}// structured LOG_ENTRIES have no typed method - call the REST endpoint.
// Send a request-matcher JSON body to filter (omit for all entries).
const response = await fetch(
"http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES",
{ method: "PUT" }
);
const entries = await response.json();
entries.forEach(function (entry) {
console.log(entry.type + " at " + entry.timestamp);
});import requests
# structured LOG_ENTRIES have no typed method - call the REST endpoint
response = requests.put(
"http://localhost:1080/mockserver/retrieve",
params={"type": "LOGS", "format": "LOG_ENTRIES"},
)
for entry in response.json():
print(entry["type"], "at", entry["timestamp"])require 'net/http'
require 'json'
# structured LOG_ENTRIES have no typed method - call the REST endpoint
uri = URI('http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES')
response = Net::HTTP.start(uri.host, uri.port) { |http| http.request(Net::HTTP::Put.new(uri)) }
JSON.parse(response.body).each do |entry|
puts "#{entry['type']} at #{entry['timestamp']}"
endimport (
"encoding/json"
"net/http"
)
// structured LOG_ENTRIES have no typed method - call the REST endpoint
req, _ := http.NewRequest("PUT", "http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES", nil)
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
var entries []map[string]interface{}
json.NewDecoder(resp.Body).Decode(&entries)
for _, entry := range entries {
fmt.Printf("%v at %v\n", entry["type"], entry["timestamp"])
}using System.Net.Http;
// structured LOG_ENTRIES have no typed method - call the REST endpoint
using var http = new HttpClient();
var response = await http.PutAsync(
"http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES", null);
var entriesJson = await response.Content.ReadAsStringAsync();use reqwest::blocking::Client;
use serde_json::Value;
// structured LOG_ENTRIES have no typed method - call the REST endpoint
let entries: Vec<Value> = Client::new()
.put("http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES")
.send()
.unwrap()
.json()
.unwrap();
for entry in &entries {
println!("{} at {}", entry["type"], entry["timestamp"]);
}use GuzzleHttp\Client;
// structured LOG_ENTRIES have no typed method - call the REST endpoint
$http = new Client();
$response = $http->put('http://localhost:1080/mockserver/retrieve', [
'query' => ['type' => 'LOGS', 'format' => 'LOG_ENTRIES'],
]);
$entries = json_decode((string) $response->getBody(), true);# use format=LOG_ENTRIES to get structured JSON log entries
curl -X PUT "http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES"LogEntry[] entries = mockServerClient.retrieveLogEntriesByCorrelationId("abc-123-def-456");// no typed method - call the REST endpoint with correlationId
const response = await fetch(
"http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES&correlationId=abc-123-def-456",
{ method: "PUT" }
);
const entries = await response.json();import requests
# no typed method - call the REST endpoint with correlationId
response = requests.put(
"http://localhost:1080/mockserver/retrieve",
params={"type": "LOGS", "format": "LOG_ENTRIES", "correlationId": "abc-123-def-456"},
)
entries = response.json()require 'net/http'
require 'json'
# no typed method - call the REST endpoint with correlationId
uri = URI('http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES&correlationId=abc-123-def-456')
response = Net::HTTP.start(uri.host, uri.port) { |http| http.request(Net::HTTP::Put.new(uri)) }
entries = JSON.parse(response.body)import (
"encoding/json"
"net/http"
)
// no typed method - call the REST endpoint with correlationId
url := "http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES&correlationId=abc-123-def-456"
req, _ := http.NewRequest("PUT", url, nil)
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
var entries []map[string]interface{}
json.NewDecoder(resp.Body).Decode(&entries)using System.Net.Http;
// no typed method - call the REST endpoint with correlationId
using var http = new HttpClient();
var response = await http.PutAsync(
"http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES&correlationId=abc-123-def-456",
null);
var entriesJson = await response.Content.ReadAsStringAsync();use reqwest::blocking::Client;
use serde_json::Value;
// no typed method - call the REST endpoint with correlationId
let url = "http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES&correlationId=abc-123-def-456";
let entries: Vec<Value> = Client::new().put(url).send().unwrap().json().unwrap();use GuzzleHttp\Client;
// no typed method - call the REST endpoint with correlationId
$http = new Client();
$response = $http->put('http://localhost:1080/mockserver/retrieve', [
'query' => [
'type' => 'LOGS',
'format' => 'LOG_ENTRIES',
'correlationId' => 'abc-123-def-456',
],
]);
$entries = json_decode((string) $response->getBody(), true);curl -X PUT "http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES&correlationId=abc-123-def-456"Time-Filtered Retrieval
When debugging intermittent issues, you can narrow log entries to a specific time window:
long now = System.currentTimeMillis();
LogEntry[] recentEntries = mockServerClient.retrieveLogEntries(
null, now - 30_000, now
);// time filtering is applied client-side on each entry's epochTime field
const now = Date.now();
const response = await fetch(
"http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES",
{ method: "PUT" }
);
const entries = await response.json();
const recentEntries = entries.filter(function (entry) {
return entry.epochTime >= now - 30000 && entry.epochTime < now;
});import time
import requests
# time filtering is applied client-side on each entry's epochTime field
now = int(time.time() * 1000)
response = requests.put(
"http://localhost:1080/mockserver/retrieve",
params={"type": "LOGS", "format": "LOG_ENTRIES"},
)
recent_entries = [
entry for entry in response.json()
if now - 30000 <= entry["epochTime"] < now
]require 'net/http'
require 'json'
# time filtering is applied client-side on each entry's epochTime field
now = (Time.now.to_f * 1000).to_i
uri = URI('http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES')
response = Net::HTTP.start(uri.host, uri.port) { |http| http.request(Net::HTTP::Put.new(uri)) }
recent_entries = JSON.parse(response.body).select do |entry|
entry['epochTime'] >= now - 30_000 && entry['epochTime'] < now
endimport (
"encoding/json"
"net/http"
"time"
)
// time filtering is applied client-side on each entry's epochTime field
now := time.Now().UnixMilli()
req, _ := http.NewRequest("PUT", "http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES", nil)
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
var entries []map[string]interface{}
json.NewDecoder(resp.Body).Decode(&entries)
var recentEntries []map[string]interface{}
for _, entry := range entries {
epochTime := int64(entry["epochTime"].(float64))
if epochTime >= now-30000 && epochTime < now {
recentEntries = append(recentEntries, entry)
}
}using System.Linq;
using System.Net.Http;
using System.Text.Json;
// time filtering is applied client-side on each entry's epochTime field
var now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
using var http = new HttpClient();
var response = await http.PutAsync(
"http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES", null);
var entries = JsonDocument.Parse(await response.Content.ReadAsStringAsync()).RootElement;
var recentEntries = entries.EnumerateArray()
.Where(entry => {
var epochTime = entry.GetProperty("epochTime").GetInt64();
return epochTime >= now - 30000 && epochTime < now;
})
.ToList();use reqwest::blocking::Client;
use serde_json::Value;
use std::time::{SystemTime, UNIX_EPOCH};
// time filtering is applied client-side on each entry's epochTime field
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as i64;
let entries: Vec<Value> = Client::new()
.put("http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES")
.send()
.unwrap()
.json()
.unwrap();
let recent_entries: Vec<&Value> = entries
.iter()
.filter(|entry| {
let epoch_time = entry["epochTime"].as_i64().unwrap_or(0);
epoch_time >= now - 30_000 && epoch_time < now
})
.collect();use GuzzleHttp\Client;
// time filtering is applied client-side on each entry's epochTime field
$now = (int) (microtime(true) * 1000);
$http = new Client();
$response = $http->put('http://localhost:1080/mockserver/retrieve', [
'query' => ['type' => 'LOGS', 'format' => 'LOG_ENTRIES'],
]);
$entries = json_decode((string) $response->getBody(), true);
$recentEntries = array_filter($entries, function ($entry) use ($now) {
return $entry['epochTime'] >= $now - 30000 && $entry['epochTime'] < $now;
});# the retrieve endpoint returns all log entries; the time window is applied
# client-side by filtering each entry on its epochTime field
curl -X PUT "http://localhost:1080/mockserver/retrieve?type=LOGS&format=LOG_ENTRIES"Related Pages
- Creating Expectations — the full reference for request matchers and response actions, so you can correct the expectation that is not matching
- Verify Requests — confirm which requests actually reached MockServer while diagnosing a mismatch
- Clearing & Resetting — rule out stale expectations or recorded requests left over from an earlier test