| Crates.io | rs-mock-server |
| lib.rs | rs-mock-server |
| version | 0.6.16 |
| created_at | 2025-07-24 23:02:53.902092+00 |
| updated_at | 2025-12-05 13:11:26.952846+00 |
| description | A simple, file-based mock API server that maps your directory structure to HTTP and GraphQL routes. Ideal for local development and testing. |
| homepage | |
| repository | https://github.com/lvendrame/rs-mock-server |
| max_upload_size | |
| id | 1767007 |
| size | 429,503 |
A simple, zero-configuration mock server built in Rust. Spin up a realistic REST API for local development or testing just by creating folders and files.
It works by scanning a directory and mapping its structure directly to API routes, with clever filename conventions for handling HTTP methods, dynamic parameters, and static assets.
Option 1: Install from crates.io (recommended)
cargo install rs-mock-server
Option 2: Download pre-built binary
Visit the GitHub Releases page and download the appropriate binary for your platform (Linux, macOS, Windows). No Rust installation required.
Option 3: Build from source
git clone https://github.com/lvendrame/rs-mock-server.git
cd rs-mock-server && cargo build --release
# Start server (uses ./mocks folder, port 4520)
rs-mock-server
# Custom port and folder
rs-mock-server --port 8080 --folder ./my-api-mocks
# Create mock directory structure
mkdir -p mocks/api/users
# Simple GET endpoint
echo '{"users": [{"id": 1, "name": "John"}]}' > mocks/api/users/get.json
# → GET /api/users
# Dynamic route with ID parameter
echo '{"id": 1, "name": "John", "email": "john@example.com"}' > mocks/api/users/get{id}.json
# → GET /api/users/123
# Full CRUD REST API
echo '[{"id": 1, "name": "John"}, {"id": 2, "name": "Jane"}]' > mocks/api/users/rest.json
# → GET, POST, PUT, PATCH, DELETE /api/users[/{id}]
| Pattern | Example | Generated Route | Description |
|---|---|---|---|
[method] |
get.json |
GET /api/users |
Basic HTTP method |
[method]{id} |
get{id}.json |
GET /api/users/{id} |
Dynamic parameter |
[method]{value} |
get{admin}.json |
GET /api/users/admin |
Specific value |
[method]{start-end} |
get{1-5}.json |
GET /api/users/1 to /5 |
Numeric range |
{id}), specific values ({admin}), and even numeric ranges ({1-10}) right from the filename.GET, POST, PUT, DELETE, PATCH, and OPTIONS endpoints.rest.json or rest.jgd files.{auth} files.{upload} folders.Content-Type if the filename doesn't match a method pattern..sql files to create GET endpoints that execute SQL queries against the in-memory database and return results as JSON.The server recursively scans a root directory (defaults to ./mocks) and translates the file and folder paths into API endpoints.
The path of each folder becomes the base URL for the routes within it.
./mocks/api/users creates the base route /api/users../mocks/api/users/profiles creates the base route /api/users/profiles.The name of a file determines the HTTP method and the final URL segment. The content of the file is served as the response body.
The following table shows how different filename patterns are mapped to routes, assuming they are inside a ./mocks/api/users directory:
| Filename Pattern | Example File | Generated Route(s) | Description |
|---|---|---|---|
[method] |
get.json |
GET /api/users |
Creates a route for a standard HTTP method. |
[method]{id} |
get{id}.json |
GET /api/users/{id} |
A dynamic segment that accepts any value in that position. |
[method]{value} |
get{admin}.json |
GET /api/users/admin |
Matches a specific, hardcoded value. |
[method]{start-end} |
get{1-5}.json |
GET /api/users/1GET /api/users/2... GET /api/users/5 |
A numeric range that generates multiple distinct routes. |
rest[{params}] |
rest.json |
GET /api/usersPOST /api/usersGET /api/users/{id}PUT /api/users/{id}PATCH /api/users/{id}DELETE /api/users/{id} |
In-Memory REST API. Creates a full CRUD API with automatic ID generation, data persistence, and initial data loading from the JSON array in the file. |
rest[{params}] |
rest.jgd |
GET /api/usersPOST /api/usersGET /api/users/{id}PUT /api/users/{id}PATCH /api/users/{id}DELETE /api/users/{id} |
In-Memory REST API with JGD. Creates a full CRUD API with dynamic fake data generation using JGD as initial data, then maintains persistence during runtime. |
{auth} |
{auth}.json |
POST /api/loginPOST /api/logout |
JWT Authentication. Creates login and logout endpoints with JWT token generation and validation middleware for route protection. |
[filename].[ext] |
avatar.png |
GET /api/users/avatar |
Static File. Any filename that doesn't match the patterns above is served as a static asset. The Content-Type header is automatically set based on the file's extension. |
[filename].jgd |
users.jgd |
GET /api/users/users |
JGD File. JSON Generation Definition files that dynamically generate realistic JSON data using the JGD-rs library. |
.sql files as GET endpoints against in-memory database.toml file to create specific configurations for your server and your routesSimple API
mkdir -p mocks/api
echo '{"status": "ok"}' > mocks/api/health.json
# → GET /api/health
CRUD REST API
echo '[{"id": 1, "name": "Product 1"}]' > mocks/products/rest.json
# → Full CRUD at /products/*
Authentication
echo '[{"username": "admin", "password": "secret"}]' > mocks/auth/{auth}.json
# → POST /auth/login, POST /auth/logout
File Uploads
mkdir mocks/{upload}
# → POST /upload, GET /upload, GET /upload/{filename}
mocks/
├── api/
│ ├── users/
│ │ ├── get.json # GET /api/users
│ │ ├── get{id}.json # GET /api/users/{id}
│ │ └── post.json # POST /api/users
│ └── products/
│ └── rest.json # Full CRUD /api/products/*
├── auth/
│ └── {auth}.json # Login/logout endpoints
├── {upload}/ # File upload endpoints
└── assets/
└── logo.png # GET /assets/logo.png
Generated Routes:
GET /api/users - List usersGET /api/users/123 - Get user by IDPOST /api/users - Create userGET,POST,PUT,DELETE /api/products/* - Full REST APIPOST /auth/login - User authenticationPOST /upload - File uploadsGET /assets/logo.png - Static assetsGET / - Homepagers-mock-server [OPTIONS]
Options:
-p, --port <PORT> Port to run the server on [default: 4520]
-f, --folder <FOLDER> Directory to load mock files from [default: mocks]
-d, --disable-cors Disable CORS, by default CORS is enabled
-a, --allowed-origin <ALLOWED_ORIGIN> Allowed origin, by default all origins are allowed
-h, --help Print help
-V, --version Print version
Clone the repository:
git clone https://github.com/lvendrame/rs-mock-server.git
cd rs-mock-server
Install dependencies:
cargo build
Set up development environment:
make dev-setup
The project includes a Makefile with convenient development commands:
# Run tests
make test
# Run tests in watch mode (requires cargo-watch)
make test-watch
# Run all quality checks (tests, clippy, formatting)
make check-all
# Format code
make fmt
# Run Clippy linter
make clippy
# Build the project
make build
# Run the application
make run
# Set up Git hooks
make setup-hooks
This project uses Git pre-commit hooks to ensure code quality. The hooks automatically:
Automatic setup: Pre-commit hooks are installed automatically when you run make dev-setup or make setup-hooks.
Manual bypass (not recommended): If you need to commit without running tests:
git commit --no-verify -m "Your message"
Configuration: You can customize the pre-commit checks by editing .git/hooks/pre-commit. The hook supports:
The project includes comprehensive test coverage:
# Run all tests
cargo test
# Run specific test module
cargo test id_manager
cargo test in_memory_collection
cargo test route_builder
# Run tests with output
cargo test -- --nocapture
git checkout -b feature-nameCode Quality: All contributions must:
cargo fmt)cargo clippy)