4 releases
Uses new Rust 2024
| 0.1.5 | Apr 7, 2026 |
|---|---|
| 0.1.4 | Apr 7, 2026 |
| 0.1.3 | Apr 7, 2026 |
| 0.1.2 | Apr 7, 2026 |
#613 in HTTP server
Used in mockpit-cli
3.5MB
32K
SLoC
Mockpit
A high-performance HTTP mocking framework for Rust with template-based response generation, HAR recording, smart consolidation, and GraphQL support.
Features
- Request Matching - Express-style (
:id), glob (**/*.json), regex, and exact URL patterns with priority-based selection - Template Responses - Tera template engine with 115+ fake data functions for realistic responses
- HAR Recording - Record live HTTP traffic and convert to mock definitions
- Smart Consolidation - Detect patterns across recordings for 90%+ size reduction
- GraphQL Support - Auto-generate mocks from GraphQL schema introspection
- Fake Data - 115+ generators: names, emails, UUIDs, images, PDFs, and more
- Stateful Mocking - Thread-safe persistence store for multi-step workflows
- Hot Reload - File watcher with debouncing for live mock editing
- HTTP API - Axum-based management API for CRUD, bulk operations, and runtime control
- CLI Tools - Commands for creating, testing, validating, serving, and converting mocks
Installation
One-line install (macOS / Linux)
curl -sSf https://raw.githubusercontent.com/salamaashoush/mockpit/main/scripts/install.sh | sh
Cargo install
cargo install mockpit-cli
From source
git clone https://github.com/salamaashoush/mockpit
cd mockpit
cargo install --path crates/mockpit-cli
Quick Start
CLI
# Create a mock
mockpit mock create "/api/users/:id" -m GET -s 200 --template
# Serve mocks with hot reload
mockpit mock serve mocks/
# Generate fake data
mockpit fake data email --count 10
# Test mock matching
mockpit mock test -m GET /api/users/123 --render
As a library
Add to your Cargo.toml:
[dependencies]
mockpit = { git = "https://github.com/salamaashoush/mockpit" }
Basic Usage
use mockpit::prelude::*;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create a mock registry and load mocks from a directory
let registry = MockRegistry::new();
registry.load_from_directory("mocks/").await?;
// Create a matcher to evaluate incoming requests
let matcher = MockMatcher::new(registry);
// Match a request
let ctx = RequestContext::new();
if let Some(action) = matcher.find_match(&ctx).await {
println!("Matched: {:?}", action);
}
Ok(())
}
Mock File Format
mocks:
- id: get-user
priority: 100
match:
methods: ["GET"]
url: "/api/users/:id"
response:
status: 200
headers:
content-type: "application/json"
template: |
{
"id": "{{ captures.id }}",
"name": "{{ fake_name() }}",
"email": "{{ fake_email() }}"
}
With HTTP Server
[dependencies]
mockpit = { git = "https://github.com/salamaashoush/mockpit", features = ["server", "api"] }
With GraphQL Support
[dependencies]
mockpit = { git = "https://github.com/salamaashoush/mockpit", features = ["graphql"] }
Feature Flags
| Feature | Default | Description |
|---|---|---|
engine |
yes | Core mock engine (includes fake-data, type-detector, codegen) |
fake-data |
yes | 115+ fake data generators |
type-detector |
no | Semantic type detection from field names and JSON values |
codegen |
no | Template code generation from detected types |
graphql |
no | GraphQL schema introspection and mock generation |
server |
no | HTTP server with hot reload and graceful shutdown |
api |
no | Mock management HTTP API (axum router) |
schema |
no | JSON schema generation for editor validation |
full |
no | Enable everything |
Crate Structure
mockpit - Library crate with feature-gated modules
mockpit-cli - CLI binary and command implementations
Documentation
- Mock Engine - Complete guide to the mocking system
- Fake Data - All 115+ generators with examples
- GraphQL Mocks - Auto-generate mocks from GraphQL schemas
- CLI Reference - All CLI commands and flags
License
MIT OR Apache-2.0
Dependencies
~24–51MB
~689K SLoC