Build a working REST API in seconds β without a backend.
Frontend blocked by an unfinished backend ?
Need stable API responses for UI tests or offline development ?
Drop JSON files into a folder and your API immediately exists.
If youβre building or testing APIs, this tool makes mocking painless. Itβs super fast, efficient, and flexible when you need it to be. All you have to do to start up is just use folders and JSON without any config set.
- βοΈ Zero-config start.
- π¬οΈ Fast to boot, light on memory.
- πͺ File-based and rule-based matching. Scripting supported.
As your project grows, your mock API grows, too. Large mock datasets often cause problems:
- Slow startup
- High memory usage
- Crashes during UI testing
- Unstable CI runs
- The backend is not ready yet.
- You need stable API responses for UI testing.
- You want offline development.
- CI tests require a predictable API.
- Your mock data is becoming large.
apimock-rs does not preload responses. Each response file is read only when a request arrives using non-blocking I/O. This keeps:
- Startup nearly instant
- Memory usage minimal
- Stable behavior under repeated requests
as validated with k6 load testing. You can run UI development and automated tests continuously without worrying about server instability.
Easy to start with npm package.
# install into your app project
npm install -D apimock-rs
# and go
npx apimock# just use folders and JSON
mkdir -p api/v1/
echo '{"hello": "world"}' > api/v1/hello.json
npx apimock
# response
curl http://localhost:3001/api/v1/hello
# --> {"hello":"world"}You may also check it out with browser to visit http://localhost:3001/api/v1/hello .
You now have a running REST endpoint.
| command | result |
|---|---|
npx apimock |
Run with all default parameters. |
npx apimock -p 4000 |
Run with custom port. |
npx apimock -d tests/apimock-dyn-route |
Run with custom root dir on server response. |
npx apimock -c apimock.toml |
Run with config file giving rich features. Running npx apimock --init beforehand is required. |
| command | result |
|---|---|
npx apimock --init |
Interactive setup. Prompts for port / IP / fallback dir / whether to scaffold a rule-set file, middleware file, and TLS section, then writes apimock.toml (and optionally apimock-rule-set.toml / apimock-middleware.rhai) customised to your answers. |
npx apimock --init --yes |
Non-interactive setup: skip every prompt and write the same defaults 4.7.0 wrote (127.0.0.1:3001, rule-set file included, TLS commented out). Useful in CI or Docker builds. |
npx apimock --init --middleware |
Also scaffold apimock-middleware.rhai. Combines with --yes. |
When stdin is not a TTY (piped, CI, Docker build), --init silently falls back to defaults even without --yes β so existing non-interactive usage of 4.7.0 keeps working unchanged.
An example of scripts section in package.json is as below.
concurrently is used to run the Vite and API mock servers simultaneously, while cross-env enables terminal output coloring. Before starting, ensure you run:
npm install -D concurrently cross-envEdit package.json:
"scripts": {
"apimock": "npx apimock",
"dev": "cross-env CLICOLOR_FORCE=1 concurrently \"vite\" \"npm run apimock\""
}Run:
npm run devFor more details, π§ check out our full documentation.
- Configuration Reference: π View all settings here
This project is lovingly built and maintained by volunteers.
We hope it helps streamline your API development.
Please understand that the project has its own direction β while we welcome feedback, it might not fit every edge case π±
Depends on tokio / hyper / toml / serde / serde_json / json5 / console / rhai / thiserror / anyhow. In addition, mdbook (as to workflows).
