WebMocks for Delphi

Stub HTTP requests in your Delphi tests. No complex setup, no boilerplate.

Apache 2.0 Free & open-source View on GitHub

Stub an HTTP endpoint and verify requests in a few lines:


var
  WebMock: TWebMock;
begin
  WebMock := TWebMock.Create;

  // Stub a JSON response
  WebMock.StubRequest('GET', '/users/1')
    .ToRespond(200, '{"id": 1, "name": "John Doe"}', 'application/json');

  // Your HTTP client hits WebMock's local server instead of a real API
  Response := HttpClient.Get(WebMock.URLFor('/users/1'));

  // Verify the request was made
  WebMock.Assert.Get('/users/1').WasRequested;
end;
      

Features

Flexible request matching.
Match requests by method, URI, headers, and body content. Combine matchers for precise control over which requests are stubbed.
Stub HTTP responses.
Define exactly what your HTTP calls return: status codes, headers, and body content. Tests stay fast and don't need a live API.
Intercept and verify.
Assert that specific requests were made during your test. Catch missing or unexpected HTTP calls without writing extra plumbing.
Fluent API.
A readable, chainable interface that keeps test setup clear. Inspired by Ruby's WebMock.

Get started

Install via RAD Studio's GetIt package manager, or clone from GitHub:

git clone https://github.com/appercept/Delphi-WebMocks.git

Full documentation and examples are on GitHub.