Retrieving Recorded Expectations

All proxied requests including those proxied using a forward actions are recorded containing the request received and response returned.

It is possible to retrieve the recorded requests and responses as expectations so that they can be easily used as expectations to simulation a system.

Expectations are returned in the order they have been recorded. The expectations are returned can be filter using a request matcher.

Expectation[] recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
    .retrieveRecordedExpectations({})
    .then(
        function (recordedExpectations) {
            console.log(JSON.stringify(recordedExpectations));
        },
        function (error) {
            console.log(error);
        }
    );

See REST API for full JSON specification

from mockserver.client import MockServerClient

client = MockServerClient("localhost", 1080)
recorded_expectations = client.retrieve_recorded_expectations()
require 'mockserver-client'

client = MockServer::Client.new('localhost', 1080)
recorded_expectations = client.retrieve_recorded_expectations
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go/v7"

client := mockserver.New("localhost", 1080)
recordedExpectations, err := client.RetrieveRecordedExpectations(nil)
using MockServer.Client;

using var client = new MockServerClient("localhost", 1080);
var recordedExpectations = client.RetrieveRecordedExpectations();
use mockserver_client::ClientBuilder;

let client = ClientBuilder::new("localhost", 1080).build().unwrap();
let recorded_expectations = client.retrieve_recorded_expectations(None).unwrap();
use MockServer\MockServerClient;

$client = new MockServerClient('localhost', 1080);
$recordedExpectations = $client->retrieveRecordedExpectations();
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS"

See REST API for full JSON specification

Expectation[] recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).retrieveRecordedExpectations({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (recordedExpectations) {
        console.log(JSON.stringify(recordedExpectations));
    },
    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)
recorded_expectations = client.retrieve_recorded_expectations(
    HttpRequest(path="/some/path", method="POST")
)
require 'mockserver-client'

client = MockServer::Client.new('localhost', 1080)
recorded_expectations = client.retrieve_recorded_expectations(
    request: MockServer::HttpRequest.new(path: '/some/path', method: 'POST')
)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go/v7"

client := mockserver.New("localhost", 1080)
recordedExpectations, err := client.RetrieveRecordedExpectations(
    mockserver.Request().Path("/some/path").Method("POST"),
)
using MockServer.Client;
using MockServer.Client.Models;

using var client = new MockServerClient("localhost", 1080);
var recordedExpectations = client.RetrieveRecordedExpectations(
    HttpRequest.Request().WithPath("/some/path").WithMethod("POST")
);
use mockserver_client::{ClientBuilder, HttpRequest};

let client = ClientBuilder::new("localhost", 1080).build().unwrap();
let filter = HttpRequest::new().path("/some/path").method("POST");
let recorded_expectations = client.retrieve_recorded_expectations(Some(&filter)).unwrap();
use MockServer\MockServerClient;
use MockServer\HttpRequest;

$client = new MockServerClient('localhost', 1080);
$recordedExpectations = $client->retrieveRecordedExpectations(
    HttpRequest::request()->path('/some/path')->method('POST')
);
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS" -d '{
    "path": "/some/path",
    "method": "POST"
}'

See REST API for full JSON specification

String recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JAVA
    );
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS&format=JAVA" -d '{
    "path": "/some/path"
}'

See REST API for full JSON specification

String recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JAVASCRIPT
    );
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS&format=JAVASCRIPT" -d '{
    "path": "/some/path"
}'

Returns copy-paste-ready code for the Node.js (mockserver-client) client, embedding each expectation's JSON in a mockAnyResponse(...) call. Also available for type=ACTIVE_EXPECTATIONS.

See REST API for full JSON specification

String recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.PYTHON
    );
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS&format=PYTHON" -d '{
    "path": "/some/path"
}'

Returns copy-paste-ready code for the Python (mockserver) client, embedding each expectation's JSON in a client.upsert(...) call. Also available for type=ACTIVE_EXPECTATIONS.

See REST API for full JSON specification

String recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.GO
    );
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS&format=GO" -d '{
    "path": "/some/path"
}'

Returns copy-paste-ready code for the Go (mockserver-client-go) client, embedding each expectation's JSON in a client.Upsert(...) call. Also available for type=ACTIVE_EXPECTATIONS.

See REST API for full JSON specification

String recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.CSHARP
    );
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS&format=CSHARP" -d '{
    "path": "/some/path"
}'

Returns copy-paste-ready code for the C# (MockServer.Client) client, embedding each expectation's JSON in a client.Upsert(...) call. Also available for type=ACTIVE_EXPECTATIONS.

See REST API for full JSON specification

String recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.RUBY
    );
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS&format=RUBY" -d '{
    "path": "/some/path"
}'

Returns copy-paste-ready code for the Ruby (mockserver-client) client, embedding each expectation's JSON in a client.upsert(...) call. Also available for type=ACTIVE_EXPECTATIONS.

See REST API for full JSON specification

String recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.RUST
    );
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS&format=RUST" -d '{
    "path": "/some/path"
}'

Returns copy-paste-ready code for the Rust (mockserver-client) crate, embedding each expectation's JSON in a client.upsert(...) call. Also available for type=ACTIVE_EXPECTATIONS.

See REST API for full JSON specification

String recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.PHP
    );
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS&format=PHP" -d '{
    "path": "/some/path"
}'

Returns copy-paste-ready code for the PHP (mock-server/mockserver-client) client, embedding each expectation's JSON in a $client->upsertExpectation(...) call. Also available for type=ACTIVE_EXPECTATIONS.

See REST API for full JSON specification

String recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JSON
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).retrieveRecordedExpectations({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (recordedExpectations) {
        console.log(JSON.stringify(recordedExpectations));
    },
    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)
# retrieve returns JSON by default
recorded_expectations = client.retrieve_recorded_expectations(
    HttpRequest(path="/some/path", method="POST")
)
require 'mockserver-client'

client = MockServer::Client.new('localhost', 1080)
# retrieve returns JSON by default
recorded_expectations = client.retrieve_recorded_expectations(
    request: MockServer::HttpRequest.new(path: '/some/path', method: 'POST')
)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go/v7"

client := mockserver.New("localhost", 1080)
// RetrieveRecordedExpectations returns JSON-parsed expectations
recordedExpectations, err := client.RetrieveRecordedExpectations(
    mockserver.Request().Path("/some/path").Method("POST"),
)
using MockServer.Client;
using MockServer.Client.Models;

using var client = new MockServerClient("localhost", 1080);
// RetrieveRecordedExpectations returns JSON-parsed expectations
var recordedExpectations = client.RetrieveRecordedExpectations(
    HttpRequest.Request().WithPath("/some/path").WithMethod("POST")
);
use mockserver_client::{ClientBuilder, HttpRequest};

let client = ClientBuilder::new("localhost", 1080).build().unwrap();
let filter = HttpRequest::new().path("/some/path").method("POST");
// retrieve_recorded_expectations returns JSON-parsed expectations
let recorded_expectations = client.retrieve_recorded_expectations(Some(&filter)).unwrap();
use MockServer\MockServerClient;
use MockServer\HttpRequest;

$client = new MockServerClient('localhost', 1080);
// retrieveRecordedExpectations returns JSON-parsed expectations
$recordedExpectations = $client->retrieveRecordedExpectations(
    HttpRequest::request()->path('/some/path')->method('POST')
);
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS&format=JSON" -d '{
    "path": "/some/path"
}'

See REST API for full JSON specification

 

Retrieving Recorded Requests

All requests the MockServer receives are recorded, including both proxied requests and requests that have matched an expectation.

It is possible to retrieve the recorded requests, as show below in the code examples.

Requests are returned in the order they have been recorded. Which requests are returned can be filter using a request matcher.

HttpRequest[] recordedRequests = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequests(
        request()
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
    .retrieveRecordedRequests({})
    .then(
        function (recordedRequests) {
            console.log(JSON.stringify(recordedRequests));
        },
        function (error) {
            console.log(error);
        }
    );

See REST API for full JSON specification

from mockserver.client import MockServerClient

client = MockServerClient("localhost", 1080)
recorded_requests = client.retrieve_recorded_requests()
require 'mockserver-client'

client = MockServer::Client.new('localhost', 1080)
recorded_requests = client.retrieve_recorded_requests
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go/v7"

client := mockserver.New("localhost", 1080)
recordedRequests, err := client.RetrieveRecordedRequests(nil)
using MockServer.Client;

using var client = new MockServerClient("localhost", 1080);
var recordedRequests = client.RetrieveRecordedRequests();
use mockserver_client::ClientBuilder;

let client = ClientBuilder::new("localhost", 1080).build().unwrap();
let recorded_requests = client.retrieve_recorded_requests(None).unwrap();
use MockServer\MockServerClient;

$client = new MockServerClient('localhost', 1080);
$recordedRequests = $client->retrieveRecordedRequests();
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS"

See REST API for full JSON specification

HttpRequest[] recordedRequests = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequests(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).retrieveRecordedRequests({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (recordedRequests) {
        console.log(JSON.stringify(recordedRequests));
    },
    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)
recorded_requests = client.retrieve_recorded_requests(
    HttpRequest(path="/some/path", method="POST")
)
require 'mockserver-client'

client = MockServer::Client.new('localhost', 1080)
recorded_requests = client.retrieve_recorded_requests(
    request: MockServer::HttpRequest.new(path: '/some/path', method: 'POST')
)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go/v7"

client := mockserver.New("localhost", 1080)
recordedRequests, err := client.RetrieveRecordedRequests(
    mockserver.Request().Path("/some/path").Method("POST"),
)
using MockServer.Client;
using MockServer.Client.Models;

using var client = new MockServerClient("localhost", 1080);
var recordedRequests = client.RetrieveRecordedRequests(
    HttpRequest.Request().WithPath("/some/path").WithMethod("POST")
);
use mockserver_client::{ClientBuilder, HttpRequest};

let client = ClientBuilder::new("localhost", 1080).build().unwrap();
let filter = HttpRequest::new().path("/some/path").method("POST");
let recorded_requests = client.retrieve_recorded_requests(Some(&filter)).unwrap();
use MockServer\MockServerClient;
use MockServer\HttpRequest;

$client = new MockServerClient('localhost', 1080);
$recordedRequests = $client->retrieveRecordedRequests(
    HttpRequest::request()->path('/some/path')->method('POST')
);
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS" -d '{
    "path": "/some/path",
    "method": "POST"
}'

See REST API for full JSON specification

String recordedRequests = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequests(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JAVA
    );
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS&format=JAVA" -d '{
    "path": "/some/path"
}'

See REST API for full JSON specification

String recordedRequests = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequests(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JSON
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).retrieveRecordedRequests({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (recordedRequests) {
        console.log(JSON.stringify(recordedRequests));
    },
    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)
# retrieve returns JSON by default
recorded_requests = client.retrieve_recorded_requests(
    HttpRequest(path="/some/path", method="POST")
)
require 'mockserver-client'

client = MockServer::Client.new('localhost', 1080)
# retrieve returns JSON by default
recorded_requests = client.retrieve_recorded_requests(
    request: MockServer::HttpRequest.new(path: '/some/path', method: 'POST')
)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go/v7"

client := mockserver.New("localhost", 1080)
// RetrieveRecordedRequests returns JSON-parsed requests
recordedRequests, err := client.RetrieveRecordedRequests(
    mockserver.Request().Path("/some/path").Method("POST"),
)
using MockServer.Client;
using MockServer.Client.Models;

using var client = new MockServerClient("localhost", 1080);
// RetrieveRecordedRequests returns JSON-parsed requests
var recordedRequests = client.RetrieveRecordedRequests(
    HttpRequest.Request().WithPath("/some/path").WithMethod("POST")
);
use mockserver_client::{ClientBuilder, HttpRequest};

let client = ClientBuilder::new("localhost", 1080).build().unwrap();
let filter = HttpRequest::new().path("/some/path").method("POST");
// retrieve_recorded_requests returns JSON-parsed requests
let recorded_requests = client.retrieve_recorded_requests(Some(&filter)).unwrap();
use MockServer\MockServerClient;
use MockServer\HttpRequest;

$client = new MockServerClient('localhost', 1080);
// retrieveRecordedRequests returns JSON-parsed requests
$recordedRequests = $client->retrieveRecordedRequests(
    HttpRequest::request()->path('/some/path')->method('POST')
);
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS&format=JSON" -d '{
    "path": "/some/path"
}'

See REST API for full JSON specification

 

Retrieve Recorded Requests & Responses

All requests the MockServer receives are recorded, including both proxied requests and requests that have matched an expectation.

It is possible to retrieve the recorded requests and their responses, as show below in the code examples.

Requests and responses are returned in the order they have been recorded. Which requests are returned can be filter using a request matcher.

HttpRequestAndHttpResponse[] httpRequestAndHttpResponse = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequestsAndResponses(
        request()
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
    .retrieveRecordedRequestsAndResponses({})
    .then(
        function (recordedRequestsAndResponses) {
            console.log(JSON.stringify(recordedRequestsAndResponses));
        },
        function (error) {
            console.log(error);
        }
    );

See REST API for full JSON specification

from mockserver.client import MockServerClient

client = MockServerClient("localhost", 1080)
recorded = client.retrieve_recorded_requests_and_responses()
require 'mockserver-client'

client = MockServer::Client.new('localhost', 1080)
recorded = client.retrieve_recorded_requests_and_responses
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go/v7"

client := mockserver.New("localhost", 1080)
// use the raw Retrieve method for request/response pairs
data, err := client.Retrieve(nil, mockserver.RetrieveRequestResponses, mockserver.FormatJSON)
using MockServer.Client;

using var client = new MockServerClient("localhost", 1080);
var recorded = client.RetrieveRecordedRequests();
// note: .NET client retrieves requests; for full request/response pairs use the REST API
use mockserver_client::ClientBuilder;

let client = ClientBuilder::new("localhost", 1080).build().unwrap();
let recorded = client.retrieve_request_responses(None).unwrap();
// no built-in request/response pair retrieve method; use curl
$ch = curl_init('http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
]);
$recorded = json_decode(curl_exec($ch), true);
curl_close($ch);
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES"

See REST API for full JSON specification

HttpRequestAndHttpResponse[] httpRequestAndHttpResponse = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequestsAndResponses(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).retrieveRecordedRequestsAndResponses({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (recordedRequestsAndResponses) {
        console.log(JSON.stringify(recordedRequestsAndResponses));
    },
    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)
recorded = client.retrieve_recorded_requests_and_responses(
    HttpRequest(path="/some/path", method="POST")
)
require 'mockserver-client'

client = MockServer::Client.new('localhost', 1080)
recorded = client.retrieve_recorded_requests_and_responses(
    request: MockServer::HttpRequest.new(path: '/some/path', method: 'POST')
)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go/v7"

client := mockserver.New("localhost", 1080)
data, err := client.Retrieve(
    mockserver.Request().Path("/some/path").Method("POST"),
    mockserver.RetrieveRequestResponses,
    mockserver.FormatJSON,
)
using System.Net.Http;
using System.Text;

using var httpClient = new HttpClient();
var json = @"{
    ""path"": ""/some/path"",
    ""method"": ""POST""
}";
var response = await httpClient.PutAsync(
    "http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES",
    new StringContent(json, Encoding.UTF8, "application/json")
);
var recorded = await response.Content.ReadAsStringAsync();
use mockserver_client::{ClientBuilder, HttpRequest};

let client = ClientBuilder::new("localhost", 1080).build().unwrap();
let filter = HttpRequest::new().path("/some/path").method("POST");
let recorded = client.retrieve_request_responses(Some(&filter)).unwrap();
{% raw %}
// no built-in request/response pair retrieve method; use curl
$ch = curl_init('http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_POSTFIELDS => json_encode(['path' => '/some/path', 'method' => 'POST']),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
]);
$recorded = json_decode(curl_exec($ch), true);
curl_close($ch);
{% endraw %}
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES" -d '{
    "path": "/some/path",
    "method": "POST"
}'

See REST API for full JSON specification

String har = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequestsAndResponses(
        request(),
        Format.HAR
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
    .retrieveRecordedRequestsAndResponsesAsHar({})
    .then(
        function (har) {
            console.log(JSON.stringify(har));
        },
        function (error) {
            console.log(error);
        }
    );

See REST API for full JSON specification

import requests

# no built-in HAR retrieve method; use the REST API directly
response = requests.put(
    "http://localhost:1080/mockserver/retrieve",
    params={"type": "REQUEST_RESPONSES", "format": "HAR"}
)
har = response.json()
require 'net/http'
require 'json'

# no built-in HAR retrieve method; use the REST API directly
uri = URI("http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES&format=HAR")
response = Net::HTTP.start(uri.host, uri.port) do |http|
    http.put(uri, '')
end
har = JSON.parse(response.body)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go/v7"

client := mockserver.New("localhost", 1080)
// use raw Retrieve with empty format to get HAR via query params
data, err := client.Retrieve(nil, "request_responses", "har")
using System.Net.Http;

// no built-in HAR retrieve method; use the REST API directly
using var httpClient = new HttpClient();
var response = await httpClient.PutAsync(
    "http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES&format=HAR",
    new StringContent("", System.Text.Encoding.UTF8, "application/json")
);
var har = await response.Content.ReadAsStringAsync();
use reqwest::blocking::Client;

// no built-in HAR retrieve method; use the REST API directly
let client = Client::new();
let response = client.put("http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES&format=HAR")
    .header("Content-Type", "application/json")
    .body("")
    .send()
    .unwrap();
let har = response.text().unwrap();
// no built-in HAR retrieve method; use curl
$ch = curl_init('http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES&format=HAR');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
]);
$har = json_decode(curl_exec($ch), true);
curl_close($ch);
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES&format=HAR"

See REST API for full JSON specification

String har = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequestsAndResponses(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.HAR
    );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).retrieveRecordedRequestsAndResponsesAsHar({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (har) {
        console.log(JSON.stringify(har));
    },
    function (error) {
        console.log(error);
    }
);

See REST API for full JSON specification

import requests

# no built-in HAR retrieve method; use the REST API directly
response = requests.put(
    "http://localhost:1080/mockserver/retrieve",
    params={"type": "REQUEST_RESPONSES", "format": "HAR"},
    json={"path": "/some/path", "method": "POST"}
)
har = response.json()
require 'net/http'
require 'json'

# no built-in HAR retrieve method; use the REST API directly
uri = URI("http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES&format=HAR")
response = Net::HTTP.start(uri.host, uri.port) do |http|
    req = Net::HTTP::Put.new(uri)
    req['Content-Type'] = 'application/json'
    req.body = JSON.generate({ path: '/some/path', method: 'POST' })
    http.request(req)
end
har = JSON.parse(response.body)
import mockserver "github.com/mock-server/mockserver-monorepo/mockserver-client-go/v7"

client := mockserver.New("localhost", 1080)
data, err := client.Retrieve(
    mockserver.Request().Path("/some/path").Method("POST"),
    "request_responses",
    "har",
)
using System.Net.Http;
using System.Text;

// no built-in HAR retrieve method; use the REST API directly
using var httpClient = new HttpClient();
var json = @"{
    ""path"": ""/some/path"",
    ""method"": ""POST""
}";
var response = await httpClient.PutAsync(
    "http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES&format=HAR",
    new StringContent(json, Encoding.UTF8, "application/json")
);
var har = await response.Content.ReadAsStringAsync();
use reqwest::blocking::Client;

// no built-in HAR retrieve method; use the REST API directly
let client = Client::new();
let response = client.put("http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES&format=HAR")
    .header("Content-Type", "application/json")
    .body(r#"{"path": "/some/path", "method": "POST"}"#.to_string())
    .send()
    .unwrap();
let har = response.text().unwrap();
{% raw %}
// no built-in HAR retrieve method; use curl
$ch = curl_init('http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES&format=HAR');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_POSTFIELDS => json_encode(['path' => '/some/path', 'method' => 'POST']),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8'],
]);
$har = json_decode(curl_exec($ch), true);
curl_close($ch);
{% endraw %}
curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES&format=HAR" -d '{
    "path": "/some/path",
    "method": "POST"
}'

See REST API for full JSON specification