---
url: https://apexfluently.beyondthecloud.dev/libraries/http-mock-lib.md
description: >-
  Mock HTTP callouts with a fluent API. No more HttpCalloutMock classes. Support
  for multiple endpoints and static resources.
---

# HTTP Mock Lib

Simplify HTTP callout testing.

::: info Documentation
You can find the full documentation at [httpmock.beyondthecloud.dev](https://httpmock.beyondthecloud.dev/).
:::

## What Does It Solve?

* **New HttpCalloutMock Class Per Endpoint** - Every endpoint requires a separate `HttpCalloutMock` class.
* **Inconsistent Mocking Approach** - Different mocking patterns for single endpoints, multiple endpoints, and static resources.

## Why Http Mock Lib?

* **Mock different HTTP methods** - Mock different HTTP methods in the same test method.
* **Fluent API** - Make your mocking English-like, no additional `HttpCalloutMock` classes required.
* **Multiple Endpoints Support** - Mock multiple callout endpoints.
* **Static Resources** - Use static resources to set callout response.

## Quick Start

❌❌❌

```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('{ "token": "aZ3Xb7Qk" }')
        .statusCodeOk()
    .whenPostOn('/api/v1/create')
        .body('{ "success": true, "message": null }')
        .statusCodeOk()
    .mock();
```

## Documentation

* [GitHub Repository](https://github.com/beyond-the-cloud-dev/http-mock-lib)

## Installation

* [Install via Unmanaged Package](https://httpmock.beyondthecloud.dev/installation#install-via-unlocked-package)
* [Deploy via Button](https://httpmock.beyondthecloud.dev/installation#deploy-via-button)
* [Copy and Deploy](https://github.com/beyond-the-cloud-dev/http-mock-lib/tree/main/force-app/main/default/classes)
