Skip to content

HTTP Mock LibFluent HTTP Mocking for Apex

A production-ready library for mocking HTTP callouts in Salesforce with a clean, fluent API

Why HTTP Mock Lib?

Traditional Salesforce HTTP mocking requires creating verbose mock classes for every test scenario. HTTP Mock Lib simplifies this with a fluent, chainable API:

apex
@IsTest
global class MockHttpResponseGenerator implements HttpCalloutMock {
    global HTTPResponse respond(HTTPRequest req) {
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'application/json');
        res.setBody('{"example":"test"}');
        res.setStatusCode(200);
        return res;
    }
}

Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
apex
new HttpMock()
  .whenGetOn('/api/v1/authorize')
  .body('{"example":"test"}')
  .statusCodeOk()
  .mock();

Part of Apex Fluently

HTTP Mock Lib is part of Apex Fluently, a suite of production-ready Salesforce libraries by Beyond the Cloud.

Get Started

Ready to simplify your HTTP mocking? Get started →