This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
mocks is a Rust CLI tool that provides instant mock REST APIs with zero coding required. It dynamically generates RESTful endpoints from JSON files, supporting full CRUD operations.
cargo build --release
cargo run -- run storage.json
cargo run -- --help # View CLI options
cargo run -- init --help # View init command options
cargo run -- run --help # View run command optionscargo test # Run all tests
cargo test storage::tests # Run specific module tests
cargo fmt -- --check # Check formatting
cargo clippy -- -D warnings # Lint with strict warningscargo llvm-cov # Generate coverage report
cargo install cargo-msrv --locked
cargo msrv find # Check MSRV compatibilitycd runn-e2e
runn run runbooks/test.yml --verbose- CLI Entry (
src/main.rs): Argument parsing with clap, server initialization - Web Server (
src/server.rs): Axum-based HTTP server with dynamic routing - Storage Layer (
src/storage.rs): File-based JSON storage with atomic operations - HTTP Handlers (
src/server/handler/): Full CRUD endpoint implementations - State Management (
src/server/state.rs): Thread-safe shared application state
- Dynamic Routing: Routes auto-generated from JSON file structure (e.g.,
api/v1/users→/api/v1/{resource}) - Async Architecture: Built on Tokio runtime with async/await throughout
- Shared State:
Arc<Mutex<AppState>>for thread-safe data access - Resource Abstraction: Uniform CRUD operations across all detected resources
- Error Mapping: Custom error types with proper HTTP status code mapping
Each JSON resource automatically gets these endpoints:
GET /{resource}- List all itemsGET /{resource}/{id}- Get specific itemPOST /{resource}- Create new itemPUT /{resource}/{id}- Replace entire itemPATCH /{resource}/{id}- Partial updateDELETE /{resource}/{id}- Delete itemGET /_hc- Health check (returns 204)
Located in src/storage/operation/:
select_all.rs,select_one.rs- Read operationsinsert.rs- Create operationsupdate.rs,update_one.rs- Update operationsreplace.rs,replace_one.rs- Replace operationsremove.rs- Delete operations
- Unit tests in
#[cfg(test)]modules within each source file - Integration tests use
tempfilefor isolated test environments - E2E tests use runn with YAML test specifications in
runn-e2e/ - Test data files use
*.test.jsonpattern
- All code must pass
cargo clippy -- -D warnings - Format code with
cargo fmt - Maintain MSRV compatibility (currently 1.78.0)
- Add comprehensive error handling with proper HTTP status codes
- Main storage file:
storage.json - Test data:
storage.test.json - Debug files:
*.debug.json(whenMOCKS_DEBUG_OVERWRITTEN_FILEis set)
mocks init storage.json # Initialize storage file
mocks init --empty storage.json # Initialize empty storage file
mocks run storage.json # Basic usage
mocks run -H 127.0.0.1 -p 8080 storage.json # Custom host/port
mocks run --no-overwrite storage.json # Prevent file modifications- Resource names in JSON must be unique (validation enforced)
- Singleton objects vs arrays are handled differently in routing
- File operations are atomic to prevent corruption
- Debug mode available via environment variable
- Health check endpoint is always available at
/_hc