Skip to content

mocks-rs/mocks

Repository files navigation

mocks

Crates.io msrv 1.80.1 codecov Ask DeepWiki License

Mock REST APIs from JSON with zero coding within seconds.

Complete Documentation - For detailed usage, advanced features, and examples.

Install

Homebrew

If you're a macOS Homebrew user, then you can install mocks from homebrew-tap.

brew install mocks-rs/tap/mocks

Cargo

If you're a Rust programmer, mocks can be installed with cargo.

cargo install mocks

npm

If you're a Node.js user, you can install mocks globally with npm.

npm install -g mocks

Alternatively, you can run mocks without installing using npx.

npx @mocks-rs/mocks init storage.json
npx @mocks-rs/mocks run storage.json

Usage

Initialize a storage file

Create a JSON file using the init command:

mocks init storage.json

This creates a storage.json file with sample data. Use the --empty option to create an empty structure:

mocks init --empty storage.json

Run a REST API server

Start the mock server using your JSON file:

mocks run storage.json

Example JSON structure:

{
  "posts": [
    { "id": "01J7BAKH37HPG116ZRRFKHBDGB", "title": "first post", "views": 100 },
    { "id": "01J7BAKH37GE8B688PT4RC7TP4", "title": "second post", "views": 10 }
  ],
  "profile": { "id": "01J7BAQE1GMD78FN3J0FJCNS8T", "name": "mocks" }
}

This automatically creates REST endpoints:

curl http://localhost:3000/posts
curl http://localhost:3000/posts/01J7BAKH37HPG116ZRRFKHBDGB
curl http://localhost:3000/profile

Documentation

For detailed information about available routes, query parameters, advanced configuration, and more features, visit the complete documentation.

For development information, see DEVELOPMENT.md.

LICENSE

This project is licensed under the MIT license.