Verifying Proxied Requests & Responses
MockServer supports verification of requests and responses it has received, including both proxied requests and requests that have matched an expectation.
Verification can be specified as follows:
- a request matcher and a condition indicating the number of times the request should be matched
- a response matcher (optionally combined with a request matcher) and a condition indicating the number of times a matching response should have been recorded
- a sequence of request matchers that is matched in order
- a sequence of request and response matcher pairs that is matched in order
How Verification Works
MockServer records all received requests in an in-memory event log (separate from application logs). Verification checks this event log:
For request matcher count verification: MockServer filters the event log to find all RECEIVED_REQUEST entries matching your request matcher, counts them, and compares the count against your constraint (atLeast(n), exactly(n), etc.). Returns HTTP 202 if the count matches, or HTTP 406 with an error message if it does not.
For response verification: When a response matcher is included in the verification, MockServer retrieves all recorded request-response pairs (from EXPECTATION_RESPONSE, FORWARDED_REQUEST, and NO_MATCH_RESPONSE entries) and filters them by the response matcher. If a request matcher is also supplied, both must match the same pair. The count of matching pairs is then checked against VerificationTimes. On failure, MockServer returns HTTP 406 with a "Response not found ..." error message listing the actual responses recorded.
For expectation ID verification: MockServer retrieves all events associated with the specified expectation ID (including EXPECTATION_RESPONSE and FORWARDED_REQUEST entries) and verifies the count.
For sequence verification: MockServer scans recorded requests in order, checking that each expected request appears after the previous match. This is not a simple count comparison—order matters. When httpResponses are included in a sequence verification, each step checks both the request and the response matcher against the same recorded exchange.
Important notes for parallel testing:
- The event log size is bounded by the
maxLogEntriesconfiguration property (default: minimum of free heap KB / 8 and 100,000 entries—see configuration). When this limit is reached, the oldest entries are evicted. If you run many parallel tests generating thousands of requests, consider increasing this value. Similarly, the number of expectations held in memory is bounded bymaxExpectations(default: minimum of free heap KB / 10 and 15,000 expectations). - Event recording uses an asynchronous ring buffer. However, verification operations are serialized through the same ring buffer in FIFO order, so a request that has reached MockServer and been recorded will be visible to subsequent verification calls. Intermittent failures are more commonly caused by:
- Your application under test sending requests asynchronously—ensure the application has completed sending before you verify
- Cross-test interference—one test's requests appearing in another test's verification
- Log eviction due to high request volume exceeding
maxLogEntries
- Best practices for parallel tests:
- Use separate MockServer instances (different ports or containers) per test for complete isolation
- If sharing an instance, use unique paths per test (e.g.,
/test/{testId}/...) or unique headers/query parameters in matchers - Avoid broad matchers like only
path("/api")in parallel tests - Be careful with
clear()orreset()—they affect all tests sharing the instance - If verification fails intermittently because your system under test is asynchronous, use retry-with-backoff to wait for requests to arrive (not to wait for MockServer to process already-received requests)
- To retrieve recorded requests for debugging, use
PUT /mockserver/retrieve?type=REQUESTSormockServerClient.retrieveRecordedRequests(null).
For more details on the internal architecture, see the Event System documentation.
Verification Timing
Note: MockServer processes log entries asynchronously using a ring buffer. When calling verify() immediately after sending requests, there may be a brief delay before log entries are available for verification. If verification fails unexpectedly right after requests are sent, add a small delay (e.g., 100ms) before retrying. This is most commonly needed in high-throughput scenarios or when the system under test sends requests asynchronously.
Verifying Repeating Requests
Verify that a request has been received by MockServer a specific number of times using a Verification
new MockServerClient("localhost", 1080)
.verify(
request()
.withPath("/some/path"),
VerificationTimes.atLeast(2)
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verify(
{
'path': '/some/path'
}, 2)
.then(
function () {
console.log("request found at least 2 times");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
from mockserver.client import MockServerClient
from mockserver.models import HttpRequest, VerificationTimes
client = MockServerClient("localhost", 1080)
client.verify(
HttpRequest(path="/some/path"),
VerificationTimes.at_least(2)
)
require 'mockserver-client'
client = MockServer::Client.new('localhost', 1080)
client.verify(
MockServer::HttpRequest.new(path: '/some/path'),
times: MockServer::VerificationTimes.at_least(2)
)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go"
client := mockserver.New("localhost", 1080)
err := client.Verify(
mockserver.Request().Path("/some/path"),
mockserver.AtLeast(2),
)
using MockServer.Client;
using MockServer.Client.Models;
using var client = new MockServerClient("localhost", 1080);
client.Verify(
HttpRequest.Request().WithPath("/some/path"),
VerificationTimes.AtLeastTimes(2)
);
use mockserver_client::{ClientBuilder, HttpRequest, VerificationTimes};
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
client.verify(
HttpRequest::new().path("/some/path"),
VerificationTimes::at_least(2),
).unwrap();
use MockServer\MockServerClient;
use MockServer\HttpRequest;
use MockServer\VerificationTimes;
$client = new MockServerClient('localhost', 1080);
$client->verify(
HttpRequest::request()->path('/some/path'),
VerificationTimes::atLeast(2)
);
curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
"httpRequest": {
"path": "/simple"
},
"times": {
"atLeast": 2
}
}'
See REST API for full JSON specification
new MockServerClient("localhost", 1080)
.verify(
request()
.withPath("/some/path"),
VerificationTimes.atMost(2)
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verify(
{
'path': '/some/path'
}, 0, 2)
.then(
function () {
console.log("request found at most 2 times");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
from mockserver.client import MockServerClient
from mockserver.models import HttpRequest, VerificationTimes
client = MockServerClient("localhost", 1080)
client.verify(
HttpRequest(path="/some/path"),
VerificationTimes.at_most(2)
)
require 'mockserver-client'
client = MockServer::Client.new('localhost', 1080)
client.verify(
MockServer::HttpRequest.new(path: '/some/path'),
times: MockServer::VerificationTimes.at_most(2)
)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go"
client := mockserver.New("localhost", 1080)
err := client.Verify(
mockserver.Request().Path("/some/path"),
mockserver.AtMost(2),
)
using MockServer.Client;
using MockServer.Client.Models;
using var client = new MockServerClient("localhost", 1080);
client.Verify(
HttpRequest.Request().WithPath("/some/path"),
VerificationTimes.AtMostTimes(2)
);
use mockserver_client::{ClientBuilder, HttpRequest, VerificationTimes};
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
client.verify(
HttpRequest::new().path("/some/path"),
VerificationTimes::at_most(2),
).unwrap();
use MockServer\MockServerClient;
use MockServer\HttpRequest;
use MockServer\VerificationTimes;
$client = new MockServerClient('localhost', 1080);
$client->verify(
HttpRequest::request()->path('/some/path'),
VerificationTimes::atMost(2)
);
curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
"httpRequest": {
"path": "/simple"
},
"times": {
"atMost": 2
}
}'
See REST API for full JSON specification
new MockServerClient("localhost", 1080)
.verify(
request()
.withPath("/some/path"),
VerificationTimes.exactly(2)
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verify(
{
'path': '/some/path'
}, 2, 2)
.then(
function () {
console.log("request found exactly 2 times");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
from mockserver.client import MockServerClient
from mockserver.models import HttpRequest, VerificationTimes
client = MockServerClient("localhost", 1080)
client.verify(
HttpRequest(path="/some/path"),
VerificationTimes.exactly(2)
)
require 'mockserver-client'
client = MockServer::Client.new('localhost', 1080)
client.verify(
MockServer::HttpRequest.new(path: '/some/path'),
times: MockServer::VerificationTimes.exactly(2)
)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go"
client := mockserver.New("localhost", 1080)
err := client.Verify(
mockserver.Request().Path("/some/path"),
mockserver.ExactlyTimes(2),
)
using MockServer.Client;
using MockServer.Client.Models;
using var client = new MockServerClient("localhost", 1080);
client.Verify(
HttpRequest.Request().WithPath("/some/path"),
VerificationTimes.ExactlyTimes(2)
);
use mockserver_client::{ClientBuilder, HttpRequest, VerificationTimes};
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
client.verify(
HttpRequest::new().path("/some/path"),
VerificationTimes::exactly(2),
).unwrap();
use MockServer\MockServerClient;
use MockServer\HttpRequest;
use MockServer\VerificationTimes;
$client = new MockServerClient('localhost', 1080);
$client->verify(
HttpRequest::request()->path('/some/path'),
VerificationTimes::exactly(2)
);
curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
"httpRequest": {
"path": "/simple"
},
"times": {
"atLeast": 2,
"atMost": 2
}
}'
See REST API for full JSON specification
new MockServerClient("localhost", 1080)
.verify(
openAPI(
"https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
),
VerificationTimes.atLeast(2)
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verify(
{
'specUrlOrPayload': 'https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json'
}, 2)
.then(
function () {
console.log("request found exactly 2 times");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
import requests
# OpenAPI matchers are not supported in the Python client verify method;
# use the REST API directly
requests.put("http://localhost:1080/mockserver/verify", json={
"httpRequest": {
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
},
"times": {
"atLeast": 2
}
})
require 'net/http'
require 'json'
# OpenAPI matchers are not supported in the Ruby client verify method;
# use the REST API directly
uri = URI("http://localhost:1080/mockserver/verify")
req = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
req.body = JSON.generate({
"httpRequest" => {
"specUrlOrPayload" => "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
},
"times" => { "atLeast" => 2 }
})
Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
package main
import (
"bytes"
"net/http"
)
func main() {
// OpenAPI matchers are not supported in the Go client;
// use the REST API directly
body := []byte(`{
"httpRequest": {
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
},
"times": {
"atLeast": 2
}
}`)
req, _ := http.NewRequest("PUT",
"http://localhost:1080/mockserver/verify",
bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
http.DefaultClient.Do(req)
}
using System.Net.Http;
using System.Text;
// OpenAPI matchers are not supported in the .NET client;
// use the REST API directly
using var httpClient = new HttpClient();
var json = @"{
""httpRequest"": {
""specUrlOrPayload"": ""https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json""
},
""times"": {
""atLeast"": 2
}
}";
await httpClient.PutAsync(
"http://localhost:1080/mockserver/verify",
new StringContent(json, Encoding.UTF8, "application/json")
);
use reqwest::blocking::Client;
// OpenAPI matchers are not supported in the Rust client;
// use the REST API directly
let client = Client::new();
let body = r#"{
"httpRequest": {
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
},
"times": {
"atLeast": 2
}
}"#;
client.put("http://localhost:1080/mockserver/verify")
.header("Content-Type", "application/json")
.body(body.to_string())
.send()
.unwrap();
// OpenAPI matchers are not supported in the PHP client;
// use the REST API directly
$ch = curl_init('http://localhost:1080/mockserver/verify');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => json_encode([
'httpRequest' => [
'specUrlOrPayload' => 'https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json',
],
'times' => ['atLeast' => 2],
]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
]);
curl_exec($ch);
curl_close($ch);
curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
"httpRequest": {
"specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
},
"times": {
"atLeast": 2
}
}'
See REST API for full JSON specification
new MockServerClient("localhost", 1080)
.verify(
openAPI(
"org/mockserver/openapi/openapi_petstore_example.json",
"showPetById"
),
VerificationTimes.once()
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verify(
{
'specUrlOrPayload': 'org/mockserver/openapi/openapi_petstore_example.json',
'operationId': 'showPetById'
}, 1, 1)
.then(
function () {
console.log("request found exactly 1 time");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
import requests
# OpenAPI matchers are not supported in the Python client verify method;
# use the REST API directly
requests.put("http://localhost:1080/mockserver/verify", json={
"httpRequest": {
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
"operationId": "showPetById"
},
"times": {
"atLeast": 1,
"atMost": 1
}
})
require 'net/http'
require 'json'
# OpenAPI matchers are not supported in the Ruby client verify method;
# use the REST API directly
uri = URI("http://localhost:1080/mockserver/verify")
req = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
req.body = JSON.generate({
"httpRequest" => {
"specUrlOrPayload" => "org/mockserver/openapi/openapi_petstore_example.json",
"operationId" => "showPetById"
},
"times" => { "atLeast" => 1, "atMost" => 1 }
})
Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
package main
import (
"bytes"
"net/http"
)
func main() {
// OpenAPI matchers are not supported in the Go client;
// use the REST API directly
body := []byte(`{
"httpRequest": {
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
"operationId": "showPetById"
},
"times": {
"atLeast": 1,
"atMost": 1
}
}`)
req, _ := http.NewRequest("PUT",
"http://localhost:1080/mockserver/verify",
bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
http.DefaultClient.Do(req)
}
using System.Net.Http;
using System.Text;
// OpenAPI matchers are not supported in the .NET client;
// use the REST API directly
using var httpClient = new HttpClient();
var json = @"{
""httpRequest"": {
""specUrlOrPayload"": ""org/mockserver/openapi/openapi_petstore_example.json"",
""operationId"": ""showPetById""
},
""times"": {
""atLeast"": 1,
""atMost"": 1
}
}";
await httpClient.PutAsync(
"http://localhost:1080/mockserver/verify",
new StringContent(json, Encoding.UTF8, "application/json")
);
use reqwest::blocking::Client;
// OpenAPI matchers are not supported in the Rust client;
// use the REST API directly
let client = Client::new();
let body = r#"{
"httpRequest": {
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
"operationId": "showPetById"
},
"times": {
"atLeast": 1,
"atMost": 1
}
}"#;
client.put("http://localhost:1080/mockserver/verify")
.header("Content-Type", "application/json")
.body(body.to_string())
.send()
.unwrap();
// OpenAPI matchers are not supported in the PHP client;
// use the REST API directly
$ch = curl_init('http://localhost:1080/mockserver/verify');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => json_encode([
'httpRequest' => [
'specUrlOrPayload' => 'org/mockserver/openapi/openapi_petstore_example.json',
'operationId' => 'showPetById',
],
'times' => ['atLeast' => 1, 'atMost' => 1],
]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
]);
curl_exec($ch);
curl_close($ch);
curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
"httpRequest": {
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
"operationId": "showPetById"
},
"times": {
"atLeast": 1,
"atMost": 1
}
}'
See REST API for full JSON specification
new MockServerClient("localhost", 1080)
.verify(
"31e4ca35-66c6-4645-afeb-6e66c4ca0559",
VerificationTimes.once()
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verifyById(
{
'id': '31e4ca35-66c6-4645-afeb-6e66c4ca0559'
}, 1, 1)
.then(
function () {
console.log("request found exactly 1 time");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
import requests
# verify by expectation ID is not supported in the Python client;
# use the REST API directly
requests.put("http://localhost:1080/mockserver/verify", json={
"expectationId": {
"id": "31e4ca35-66c6-4645-afeb-6e66c4ca0559"
}
})
require 'net/http'
require 'json'
# verify by expectation ID is not supported in the Ruby client;
# use the REST API directly
uri = URI("http://localhost:1080/mockserver/verify")
req = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
req.body = JSON.generate({
"expectationId" => {
"id" => "31e4ca35-66c6-4645-afeb-6e66c4ca0559"
}
})
Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
package main
import (
"bytes"
"net/http"
)
func main() {
// verify by expectation ID is not supported in the Go client;
// use the REST API directly
body := []byte(`{"expectationId": {"id": "31e4ca35-66c6-4645-afeb-6e66c4ca0559"}}`)
req, _ := http.NewRequest("PUT",
"http://localhost:1080/mockserver/verify",
bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
http.DefaultClient.Do(req)
}
using System.Net.Http;
using System.Text;
// verify by expectation ID is not supported in the .NET client;
// use the REST API directly
using var httpClient = new HttpClient();
var json = @"{""expectationId"": {""id"": ""31e4ca35-66c6-4645-afeb-6e66c4ca0559""}}";
await httpClient.PutAsync(
"http://localhost:1080/mockserver/verify",
new StringContent(json, Encoding.UTF8, "application/json")
);
use reqwest::blocking::Client;
// verify by expectation ID is not supported in the Rust client;
// use the REST API directly
let client = Client::new();
client.put("http://localhost:1080/mockserver/verify")
.header("Content-Type", "application/json")
.body(r#"{"expectationId": {"id": "31e4ca35-66c6-4645-afeb-6e66c4ca0559"}}"#.to_string())
.send()
.unwrap();
// verify by expectation ID is not supported in the PHP client;
// use the REST API directly
$ch = curl_init('http://localhost:1080/mockserver/verify');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => json_encode(['expectationId' => ['id' => '31e4ca35-66c6-4645-afeb-6e66c4ca0559']]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
]);
curl_exec($ch);
curl_close($ch);
curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
"expectationId": {
"id": "31e4ca35-66c6-4645-afeb-6e66c4ca0559"
}
}'
See REST API for full JSON specification
new MockServerClient("localhost", 1080)
.verify(
request()
.withPath("/some/path"),
VerificationTimes.exactly(0)
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verify(
{
'path': '/some/path'
}, 0, 0)
.then(
function () {
console.log("request found zero times");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
from mockserver.client import MockServerClient
from mockserver.models import HttpRequest, VerificationTimes
client = MockServerClient("localhost", 1080)
client.verify(
HttpRequest(path="/some/path"),
VerificationTimes.exactly(0)
)
require 'mockserver-client'
client = MockServer::Client.new('localhost', 1080)
client.verify(
MockServer::HttpRequest.new(path: '/some/path'),
times: MockServer::VerificationTimes.at_most(0)
)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go"
client := mockserver.New("localhost", 1080)
err := client.Verify(
mockserver.Request().Path("/some/path"),
mockserver.AtMost(0),
)
using MockServer.Client;
using MockServer.Client.Models;
using var client = new MockServerClient("localhost", 1080);
client.Verify(
HttpRequest.Request().WithPath("/some/path"),
VerificationTimes.AtMostTimes(0)
);
use mockserver_client::{ClientBuilder, HttpRequest, VerificationTimes};
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
client.verify(
HttpRequest::new().path("/some/path"),
VerificationTimes::exactly(0),
).unwrap();
use MockServer\MockServerClient;
use MockServer\HttpRequest;
use MockServer\VerificationTimes;
$client = new MockServerClient('localhost', 1080);
$client->verify(
HttpRequest::request()->path('/some/path'),
VerificationTimes::exactly(0)
);
curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
"httpRequest": {
"path": "/simple"
},
"times": {
"atMost": 0
}
}'
See REST API for full JSON specification
Unlike verify requests never received above (which checks a specific request matcher was matched zero times), verifyZeroInteractions() verifies that no requests of any kind have been received by MockServer. It is equivalent to verifying a match-all request matcher with exactly(0).
new MockServerClient("localhost", 1080)
.verifyZeroInteractions();
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verifyZeroInteractions()
.then(
function () {
console.log("no requests received");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
from mockserver.client import MockServerClient
client = MockServerClient("localhost", 1080)
client.verify_zero_interactions()
require 'mockserver-client'
client = MockServer::Client.new('localhost', 1080)
client.verify_zero_interactions
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go"
client := mockserver.New("localhost", 1080)
// verify that no requests were received
err := client.Verify(
mockserver.Request(),
mockserver.AtMost(0),
)
using MockServer.Client;
using MockServer.Client.Models;
using var client = new MockServerClient("localhost", 1080);
// verify that no requests were received
client.Verify(
HttpRequest.Request(),
VerificationTimes.AtMostTimes(0)
);
use mockserver_client::{ClientBuilder, HttpRequest, VerificationTimes};
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
// verify that no requests were received
client.verify(
HttpRequest::new(),
VerificationTimes::at_most(0),
).unwrap();
use MockServer\MockServerClient;
use MockServer\HttpRequest;
use MockServer\VerificationTimes;
$client = new MockServerClient('localhost', 1080);
// verify that no requests were received
$client->verify(
HttpRequest::request(),
VerificationTimes::exactly(0)
);
curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
"httpRequest": {},
"times": {
"atMost": 0
}
}'
See REST API for full JSON specification
Verifying Responses
MockServer can verify the responses recorded from proxied/forwarded upstream systems, or from served expectations. This is especially useful when MockServer acts as a proxy in front of a system under test (SUT) — you can assert not only that the correct requests were sent, but that the SUT returned the expected responses.
When a response matcher is supplied in a verification, MockServer switches from counting received requests to counting recorded request-response pairs whose response matches. The response matcher can match by:
- Status code — exact match (e.g.,
200,404) - Reason phrase — regex match
- Headers — same header matching as request matchers (subset match, multi-value)
- Body — the same body matchers available for request bodies: JSON, JSON Schema, JSONPath, XML, XPath, regex, sub-string, binary, etc.
If both a request matcher and a response matcher are supplied, both must match the same recorded exchange. VerificationTimes (atLeast, atMost, exactly) applies to the count of matching pairs, exactly like request verification.
REST API: PUT /mockserver/verify with body { "httpRequest": {...}, "httpResponse": {...}, "times": {...} }. Returns HTTP 202 on pass, or HTTP 406 with a "Response not found ..." error message on failure. The request matcher is optional — omit it to match responses regardless of which request produced them.
new MockServerClient("localhost", 1080)
.verify(
request()
.withPath("/some/path"),
response()
.withStatusCode(200)
.withBody(json("{\"status\": \"ok\"}")),
VerificationTimes.atLeast(1)
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verify(
{
'path': '/some/path'
},
{
'statusCode': 200,
'body': JSON.stringify({status: 'ok'})
}, 1)
.then(
function () {
console.log("matching request-response pair found at least once");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
from mockserver.client import MockServerClient
from mockserver.models import HttpRequest, HttpResponse, VerificationTimes
client = MockServerClient("localhost", 1080)
client.verify(
HttpRequest(path="/some/path"),
HttpResponse(status_code=200, body='{"status": "ok"}'),
VerificationTimes.at_least(1)
)
require 'mockserver-client'
client = MockServer::Client.new('localhost', 1080)
client.verify(
MockServer::HttpRequest.new(path: '/some/path'),
MockServer::HttpResponse.new(status_code: 200, body: '{"status": "ok"}'),
times: MockServer::VerificationTimes.at_least(1)
)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go"
client := mockserver.New("localhost", 1080)
err := client.Verify(
mockserver.Request().Path("/some/path"),
mockserver.Response().StatusCode(200).Body(`{"status": "ok"}`),
mockserver.AtLeast(1),
)
using MockServer.Client;
using MockServer.Client.Models;
using var client = new MockServerClient("localhost", 1080);
client.Verify(
HttpRequest.Request().WithPath("/some/path"),
HttpResponse.Response().WithStatusCode(200).WithBody("{\"status\": \"ok\"}"),
VerificationTimes.AtLeastTimes(1)
);
use mockserver_client::{ClientBuilder, HttpRequest, HttpResponse, VerificationTimes};
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
client.verify_with_response(
HttpRequest::new().path("/some/path"),
HttpResponse::new().status_code(200).body(r#"{"status": "ok"}"#),
VerificationTimes::at_least(1),
).unwrap();
use MockServer\MockServerClient;
use MockServer\HttpRequest;
use MockServer\HttpResponse;
use MockServer\VerificationTimes;
$client = new MockServerClient('localhost', 1080);
$client->verify(
HttpRequest::request()->path('/some/path'),
HttpResponse::response()->statusCode(200)->body('{"status": "ok"}'),
VerificationTimes::atLeast(1)
);
curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
"httpRequest": {
"path": "/some/path"
},
"httpResponse": {
"statusCode": 200,
"body": "{\"status\": \"ok\"}"
},
"times": {
"atLeast": 1
}
}'
See REST API for full JSON specification
When no request matcher is supplied, MockServer matches responses from all recorded request-response pairs. This is useful when you want to verify that a particular response was returned regardless of which request produced it.
new MockServerClient("localhost", 1080)
.verify(
response()
.withStatusCode(200)
.withHeaders(
header("Content-Type", "application/json")
),
VerificationTimes.atLeast(1)
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verify(
null,
{
'statusCode': 200,
'headers': {
'Content-Type': ['application/json']
}
}, 1)
.then(
function () {
console.log("matching response found at least once");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
from mockserver.client import MockServerClient
from mockserver.models import HttpResponse, VerificationTimes
client = MockServerClient("localhost", 1080)
client.verify(
HttpResponse(status_code=200, headers={"Content-Type": "application/json"}),
VerificationTimes.at_least(1)
)
require 'mockserver-client'
client = MockServer::Client.new('localhost', 1080)
client.verify(
MockServer::HttpResponse.new(
status_code: 200,
headers: { 'Content-Type' => 'application/json' }
),
times: MockServer::VerificationTimes.at_least(1)
)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go"
client := mockserver.New("localhost", 1080)
err := client.VerifyResponse(
mockserver.Response().StatusCode(200).
Header("Content-Type", "application/json"),
mockserver.AtLeast(1),
)
using MockServer.Client;
using MockServer.Client.Models;
using var client = new MockServerClient("localhost", 1080);
client.Verify(
HttpResponse.Response().WithStatusCode(200)
.WithHeader("Content-Type", "application/json"),
VerificationTimes.AtLeastTimes(1)
);
use mockserver_client::{ClientBuilder, HttpResponse, VerificationTimes};
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
client.verify_response(
HttpResponse::new().status_code(200)
.header("Content-Type", "application/json"),
VerificationTimes::at_least(1),
).unwrap();
use MockServer\MockServerClient;
use MockServer\HttpResponse;
use MockServer\VerificationTimes;
$client = new MockServerClient('localhost', 1080);
$client->verify(
HttpResponse::response()->statusCode(200)
->header('Content-Type', 'application/json'),
VerificationTimes::atLeast(1)
);
curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
"httpResponse": {
"statusCode": 200,
"headers": {
"Content-Type": ["application/json"]
}
},
"times": {
"atLeast": 1
}
}'
See REST API for full JSON specification
Response body matchers support the same matching types as request body matchers, including JSON Schema. This example verifies that a response was recorded whose body conforms to a given JSON Schema.
new MockServerClient("localhost", 1080)
.verify(
request()
.withPath("/api/users"),
response()
.withStatusCode(200)
.withBody(jsonSchema("{" +
" \"type\": \"object\"," +
" \"required\": [\"id\", \"name\"]," +
" \"properties\": {" +
" \"id\": { \"type\": \"integer\" }," +
" \"name\": { \"type\": \"string\" }" +
" }" +
"}")),
VerificationTimes.atLeast(1)
);
curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
"httpRequest": {
"path": "/api/users"
},
"httpResponse": {
"statusCode": 200,
"body": {
"type": "JSON_SCHEMA",
"jsonSchema": "{\"type\":\"object\",\"required\":[\"id\",\"name\"],\"properties\":{\"id\":{\"type\":\"integer\"},\"name\":{\"type\":\"string\"}}}"
}
},
"times": {
"atLeast": 1
}
}'
See REST API for full JSON specification
Verifying Request Sequences
Verify that a sequence of requests has been received by MockServer in the specified order using a VerificationSequence
The each request in the sequence will be verified to have been received at least once, in the exact order specified.
new MockServerClient("localhost", 1080)
.verify(
request()
.withPath("/some/path/one"),
request()
.withPath("/some/path/two"),
request()
.withPath("/some/path/three")
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verifySequence(
{
'path': '/some/path/one'
},
{
'path': '/some/path/two'
},
{
'path': '/some/path/three'
}
)
.then(
function () {
console.log("request sequence found in the order specified");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
from mockserver.client import MockServerClient
from mockserver.models import HttpRequest
client = MockServerClient("localhost", 1080)
client.verify_sequence(
HttpRequest(path="/some/path/one"),
HttpRequest(path="/some/path/two"),
HttpRequest(path="/some/path/three"),
)
require 'mockserver-client'
client = MockServer::Client.new('localhost', 1080)
client.verify_sequence(
MockServer::HttpRequest.new(path: '/some/path/one'),
MockServer::HttpRequest.new(path: '/some/path/two'),
MockServer::HttpRequest.new(path: '/some/path/three'),
)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go"
client := mockserver.New("localhost", 1080)
err := client.VerifySequence(
mockserver.Request().Path("/some/path/one"),
mockserver.Request().Path("/some/path/two"),
mockserver.Request().Path("/some/path/three"),
)
using MockServer.Client;
using MockServer.Client.Models;
using var client = new MockServerClient("localhost", 1080);
client.VerifySequence(
HttpRequest.Request().WithPath("/some/path/one"),
HttpRequest.Request().WithPath("/some/path/two"),
HttpRequest.Request().WithPath("/some/path/three")
);
use mockserver_client::{ClientBuilder, HttpRequest};
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
client.verify_sequence(vec![
HttpRequest::new().path("/some/path/one"),
HttpRequest::new().path("/some/path/two"),
HttpRequest::new().path("/some/path/three"),
]).unwrap();
use MockServer\MockServerClient;
use MockServer\HttpRequest;
$client = new MockServerClient('localhost', 1080);
$client->verifySequence(
HttpRequest::request()->path('/some/path/one'),
HttpRequest::request()->path('/some/path/two'),
HttpRequest::request()->path('/some/path/three')
);
curl -v -X PUT "http://localhost:1080/mockserver/verifySequence" -d '{
"httpRequests":[
{
"path":"/some/path/one"
},
{
"path":"/some/path/two"
},
{
"path":"/some/path/three"
}
]
}'
See REST API for full JSON specification
new MockServerClient("localhost", 1080)
.verify(
request()
.withPath("/status"),
openAPI(
"org/mockserver/openapi/openapi_petstore_example.json",
"listPets"
),
openAPI(
"org/mockserver/openapi/openapi_petstore_example.json",
"showPetById"
)
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verifySequence(
{
'path': '/status'
},
{
'specUrlOrPayload': 'org/mockserver/openapi/openapi_petstore_example.json',
'operationId': 'listPets'
},
{
'specUrlOrPayload': 'org/mockserver/openapi/openapi_petstore_example.json',
'operationId': 'showPetById'
}
)
.then(
function () {
console.log("request sequence found in the order specified");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
import requests
# OpenAPI matchers in verification sequences are not supported in the
# Python client; use the REST API directly
requests.put("http://localhost:1080/mockserver/verifySequence", json={
"httpRequests": [
{"path": "/status"},
{
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
"operationId": "listPets"
},
{
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
"operationId": "showPetById"
}
]
})
require 'net/http'
require 'json'
# OpenAPI matchers in verification sequences are not supported in the
# Ruby client; use the REST API directly
uri = URI("http://localhost:1080/mockserver/verifySequence")
req = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
req.body = JSON.generate({
"httpRequests" => [
{ "path" => "/status" },
{
"specUrlOrPayload" => "org/mockserver/openapi/openapi_petstore_example.json",
"operationId" => "listPets"
},
{
"specUrlOrPayload" => "org/mockserver/openapi/openapi_petstore_example.json",
"operationId" => "showPetById"
}
]
})
Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
package main
import (
"bytes"
"net/http"
)
func main() {
// OpenAPI matchers are not supported in the Go client;
// use the REST API directly
body := []byte(`{
"httpRequests":[
{"path": "/status"},
{
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
"operationId": "listPets"
},
{
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
"operationId": "showPetById"
}
]
}`)
req, _ := http.NewRequest("PUT",
"http://localhost:1080/mockserver/verifySequence",
bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
http.DefaultClient.Do(req)
}
using System.Net.Http;
using System.Text;
// OpenAPI matchers are not supported in the .NET client;
// use the REST API directly
using var httpClient = new HttpClient();
var json = @"{
""httpRequests"":[
{""path"": ""/status""},
{
""specUrlOrPayload"": ""org/mockserver/openapi/openapi_petstore_example.json"",
""operationId"": ""listPets""
},
{
""specUrlOrPayload"": ""org/mockserver/openapi/openapi_petstore_example.json"",
""operationId"": ""showPetById""
}
]
}";
await httpClient.PutAsync(
"http://localhost:1080/mockserver/verifySequence",
new StringContent(json, Encoding.UTF8, "application/json")
);
use reqwest::blocking::Client;
// OpenAPI matchers are not supported in the Rust client;
// use the REST API directly
let client = Client::new();
let body = r#"{
"httpRequests":[
{"path": "/status"},
{
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
"operationId": "listPets"
},
{
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
"operationId": "showPetById"
}
]
}"#;
client.put("http://localhost:1080/mockserver/verifySequence")
.header("Content-Type", "application/json")
.body(body.to_string())
.send()
.unwrap();
// OpenAPI matchers in verification sequences are not supported in the
// PHP client; use the REST API directly
$ch = curl_init('http://localhost:1080/mockserver/verifySequence');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => json_encode([
'httpRequests' => [
['path' => '/status'],
[
'specUrlOrPayload' => 'org/mockserver/openapi/openapi_petstore_example.json',
'operationId' => 'listPets',
],
[
'specUrlOrPayload' => 'org/mockserver/openapi/openapi_petstore_example.json',
'operationId' => 'showPetById',
],
],
]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
]);
curl_exec($ch);
curl_close($ch);
curl -v -X PUT "http://localhost:1080/mockserver/verifySequence" -d '{
"httpRequests":[
{
"path": "/status"
},
{
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
"operationId": "listPets"
},
{
"specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
"operationId": "showPetById"
}
]
}'
See REST API for full JSON specification
new MockServerClient("localhost", 1080)
.verify(
"31e4ca35-66c6-4645-afeb-6e66c4ca0559",
"66c6ca35-ca35-66f5-8feb-5e6ac7ca0559",
"ca3531e4-23c8-ff45-88f5-4ca0c7ca0559"
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verifySequenceById(
{
'id': '31e4ca35-66c6-4645-afeb-6e66c4ca0559'
},
{
'id': '66c6ca35-ca35-66f5-8feb-5e6ac7ca0559'
},
{
'id': 'ca3531e4-23c8-ff45-88f5-4ca0c7ca0559'
}
)
.then(
function () {
console.log("request sequence found in the order specified");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
import requests
# verify sequence by expectation IDs is not supported in the Python
# client; use the REST API directly
requests.put("http://localhost:1080/mockserver/verifySequence", json={
"expectationIds": [
{"id": "31e4ca35-66c6-4645-afeb-6e66c4ca0559"},
{"id": "66c6ca35-ca35-66f5-8feb-5e6ac7ca0559"},
{"id": "ca3531e4-23c8-ff45-88f5-4ca0c7ca0559"}
]
})
require 'net/http'
require 'json'
# verify sequence by expectation IDs is not supported in the Ruby
# client; use the REST API directly
uri = URI("http://localhost:1080/mockserver/verifySequence")
req = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
req.body = JSON.generate({
"expectationIds" => [
{ "id" => "31e4ca35-66c6-4645-afeb-6e66c4ca0559" },
{ "id" => "66c6ca35-ca35-66f5-8feb-5e6ac7ca0559" },
{ "id" => "ca3531e4-23c8-ff45-88f5-4ca0c7ca0559" }
]
})
Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
package main
import (
"bytes"
"net/http"
)
func main() {
// verify sequence by expectation IDs is not supported in the Go
// client; use the REST API directly
body := []byte(`{
"expectationIds": [
{"id": "31e4ca35-66c6-4645-afeb-6e66c4ca0559"},
{"id": "66c6ca35-ca35-66f5-8feb-5e6ac7ca0559"},
{"id": "ca3531e4-23c8-ff45-88f5-4ca0c7ca0559"}
]
}`)
req, _ := http.NewRequest("PUT",
"http://localhost:1080/mockserver/verifySequence",
bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
http.DefaultClient.Do(req)
}
using System.Net.Http;
using System.Text;
// verify sequence by expectation IDs is not supported in the .NET
// client; use the REST API directly
using var httpClient = new HttpClient();
var json = @"{
""expectationIds"": [
{""id"": ""31e4ca35-66c6-4645-afeb-6e66c4ca0559""},
{""id"": ""66c6ca35-ca35-66f5-8feb-5e6ac7ca0559""},
{""id"": ""ca3531e4-23c8-ff45-88f5-4ca0c7ca0559""}
]
}";
await httpClient.PutAsync(
"http://localhost:1080/mockserver/verifySequence",
new StringContent(json, Encoding.UTF8, "application/json")
);
use reqwest::blocking::Client;
// verify sequence by expectation IDs is not supported in the Rust
// client; use the REST API directly
let client = Client::new();
let body = r#"{
"expectationIds": [
{"id": "31e4ca35-66c6-4645-afeb-6e66c4ca0559"},
{"id": "66c6ca35-ca35-66f5-8feb-5e6ac7ca0559"},
{"id": "ca3531e4-23c8-ff45-88f5-4ca0c7ca0559"}
]
}"#;
client.put("http://localhost:1080/mockserver/verifySequence")
.header("Content-Type", "application/json")
.body(body.to_string())
.send()
.unwrap();
// verify sequence by expectation IDs is not supported in the PHP
// client; use the REST API directly
$ch = curl_init('http://localhost:1080/mockserver/verifySequence');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => json_encode([
'expectationIds' => [
['id' => '31e4ca35-66c6-4645-afeb-6e66c4ca0559'],
['id' => '66c6ca35-ca35-66f5-8feb-5e6ac7ca0559'],
['id' => 'ca3531e4-23c8-ff45-88f5-4ca0c7ca0559'],
],
]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
]);
curl_exec($ch);
curl_close($ch);
curl -v -X PUT "http://localhost:1080/mockserver/verifySequence" -d '{
"expectationIds": [
{
"id": "31e4ca35-66c6-4645-afeb-6e66c4ca0559"
},
{
"id": "66c6ca35-ca35-66f5-8feb-5e6ac7ca0559"
},
{
"id": "ca3531e4-23c8-ff45-88f5-4ca0c7ca0559"
}
]
}'
See REST API for full JSON specification
You can verify that a sequence of request-response pairs was recorded in order. Each step in the sequence can include a request matcher, a response matcher, or both. The httpRequests and httpResponses arrays are matched by index — httpRequests[0] is paired with httpResponses[0], and so on. Either array element can be omitted (or null) to act as a wildcard for that side of the pair.
new MockServerClient("localhost", 1080)
.verify(
verificationSequence()
.withRequests(
request().withPath("/api/login"),
request().withPath("/api/data")
)
.withResponses(
response().withStatusCode(200),
response().withStatusCode(200)
.withBody(json("{\"result\": \"success\"}"))
)
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verifySequence(
{
httpRequests: [
{ 'path': '/api/login' },
{ 'path': '/api/data' }
],
httpResponses: [
{ 'statusCode': 200 },
{ 'statusCode': 200, 'body': JSON.stringify({result: 'success'}) }
]
}
)
.then(
function () {
console.log("request-response sequence found in the order specified");
},
function (error) {
console.log(error);
}
);
See REST API for full JSON specification
from mockserver.client import MockServerClient
from mockserver.models import HttpRequest, HttpResponse
client = MockServerClient("localhost", 1080)
client.verify_sequence(
requests=[
HttpRequest(path="/api/login"),
HttpRequest(path="/api/data"),
],
responses=[
HttpResponse(status_code=200),
HttpResponse(status_code=200, body='{"result": "success"}'),
]
)
require 'mockserver-client'
client = MockServer::Client.new('localhost', 1080)
client.verify_sequence(
requests: [
MockServer::HttpRequest.new(path: '/api/login'),
MockServer::HttpRequest.new(path: '/api/data'),
],
responses: [
MockServer::HttpResponse.new(status_code: 200),
MockServer::HttpResponse.new(status_code: 200, body: '{"result": "success"}'),
]
)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go"
client := mockserver.New("localhost", 1080)
err := client.VerifySequenceWithResponses(
[]mockserver.RequestDefinition{
mockserver.Request().Path("/api/login"),
mockserver.Request().Path("/api/data"),
},
[]mockserver.HttpResponse{
mockserver.Response().StatusCode(200),
mockserver.Response().StatusCode(200).Body(`{"result": "success"}`),
},
)
using MockServer.Client;
using MockServer.Client.Models;
using var client = new MockServerClient("localhost", 1080);
client.VerifySequence(
new[] {
HttpRequest.Request().WithPath("/api/login"),
HttpRequest.Request().WithPath("/api/data")
},
new[] {
HttpResponse.Response().WithStatusCode(200),
HttpResponse.Response().WithStatusCode(200).WithBody("{\"result\": \"success\"}")
}
);
use mockserver_client::{ClientBuilder, HttpRequest, HttpResponse};
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
client.verify_sequence_with_responses(
vec![
HttpRequest::new().path("/api/login"),
HttpRequest::new().path("/api/data"),
],
vec![
HttpResponse::new().status_code(200),
HttpResponse::new().status_code(200).body(r#"{"result": "success"}"#),
],
).unwrap();
use MockServer\MockServerClient;
use MockServer\HttpRequest;
use MockServer\HttpResponse;
$client = new MockServerClient('localhost', 1080);
$client->verifySequence(
[
HttpRequest::request()->path('/api/login'),
HttpRequest::request()->path('/api/data'),
],
[
HttpResponse::response()->statusCode(200),
HttpResponse::response()->statusCode(200)->body('{"result": "success"}'),
]
);
curl -v -X PUT "http://localhost:1080/mockserver/verifySequence" -d '{
"httpRequests": [
{
"path": "/api/login"
},
{
"path": "/api/data"
}
],
"httpResponses": [
{
"statusCode": 200
},
{
"statusCode": 200,
"body": "{\"result\": \"success\"}"
}
]
}'
See REST API for full JSON specification