MockIt is a REST API mocking library for JavaScript and TypeScript.
It supports three runtime patterns:
MockServer: run a real mock API on a local portHttpInterceptor: intercept outbound HTTP in the current Node processRemoteMockServer: change a runningMockServerfrom tests or scripts
| Feature | Use case |
|---|---|
MockServer |
Run a real mock API server for frontend development, browser automation, or any other process that needs a URL to call. |
HttpInterceptor |
Intercept fetch, http, https, and Axios inside the current Node process without starting a server. |
RemoteMockServer |
Update a running standalone mock from Playwright, API tests, or external scripts. |
| TypeScript defaults | Load reusable default mocks from a typed config file. |
| OpenAPI / Swagger loading | Generate mock endpoints and sample responses from an API spec. |
| Request matching | Match by method, headers, cookies, query, bearer token, and body. |
| Response control | Return delays, templates, faults, sequences, and limited-use responses. |
| Dashboard and admin APIs | Inspect mocks, requests, unmatched calls, and pending expectations. |
Live docs: https://toolstackhq.github.io/mockit/
Install:
npm install @toolstackhq/mockitUse MockServer when:
- a browser, UI, or another process must call a real HTTP endpoint
- you want a mock to stay running outside a test process
- manual testers or QA automation need a stable fake backend
Use HttpInterceptor when:
- the code under test already runs in Node
- you want to fake outbound HTTP without starting a server
- your Node code uses
fetch, Axios,http, orhttps
Use RemoteMockServer when:
MockServeris already running- the test should change mock behavior without starting the server itself
Create a TypeScript config:
npx @toolstackhq/mockit initIn a terminal, init can either:
- write the default starter config
- ask a few questions and generate endpoints for you
Start a standalone mock:
npx @toolstackhq/mockit serve --config ./mockit.config.ts --port 3001The dashboard is available at:
http://127.0.0.1:3001/_mockitimport { defineConfig } from '@toolstackhq/mockit';
export default defineConfig([
{
path: '/api/balance',
method: 'GET',
response: {
status: 200,
body: { balance: 200, currency: 'AUD' },
},
},
]);Use HttpInterceptor when your code already runs in Node and you do not want to start a mock server.
import axios from 'axios';
import { HttpInterceptor } from '@toolstackhq/mockit';
const interceptor = new HttpInterceptor({ onUnhandled: 'fail' });
interceptor.expect('/api/users')
.method('GET')
.returns(200)
.withBody([{ id: 1, name: 'Jane Doe' }]);
interceptor.enable();
const response = await axios.get('https://api.example.com/api/users');
console.log(response.data);
interceptor.disable();The request still looks like a real outbound HTTP call, but MockIt returns the response inside the same Node process.
{
"scripts": {
"mockit": "mockit serve --config ./mockit.config.ts --port 3001"
}
}