MockForge Core
Core functionality and shared logic for the MockForge mocking framework.
This crate provides the foundational building blocks used across all MockForge protocols (HTTP, WebSocket, gRPC, GraphQL). It can be used as a library to programmatically create and manage mock servers, or to build custom mocking solutions.
Overview
MockForge Core includes:
- Routing & Validation: OpenAPI-based route registration and request validation
- Request/Response Processing: Template expansion, data generation, and transformation
- Chaos Engineering: Latency injection, failure simulation, and traffic shaping
- Proxy & Hybrid Mode: Forward requests to real backends with intelligent fallback
- Request Chaining: Multi-step request workflows with context passing
- Workspace Management: Organize and persist mock configurations
- Observability: Request logging, metrics collection, and tracing
Quick Start: Embedding MockForge
Creating a Simple HTTP Mock Server
use ;
async
Request Chaining
Chain multiple requests together with shared context:
use ;
# async
Latency & Failure Injection
Simulate realistic network conditions and errors:
use ;
// Configure latency simulation
let latency = slow; // 300-800ms
// Configure failure injection
let failure_config = FailureConfig ;
let injector = create_failure_injector;
Key Modules
OpenAPI Support
- [
openapi
]: Parse and work with OpenAPI specifications - [
openapi_routes
]: Register routes from OpenAPI specs with validation - [
validation
]: Request/response validation against schemas
Request Processing
- [
routing
]: Route matching and registration - [
templating
]: Template variable expansion ({{uuid}}, {{now}}, etc.) - [
request_chaining
]: Multi-step request workflows - [
overrides
]: Dynamic request/response modifications
Chaos Engineering
- [
latency
]: Latency injection with configurable profiles - [
failure_injection
]: Simulate service failures and errors - [
traffic_shaping
]: Bandwidth limiting and packet loss
Proxy & Hybrid
- [
proxy
]: Forward requests to upstream services - [
ws_proxy
]: WebSocket proxy with message transformation
Persistence & Import
- [
workspace
]: Workspace management for organizing mocks - [
workspace_import
]: Import from Postman, Insomnia, cURL, HAR - [
record_replay
]: Record real requests and replay as fixtures
Observability
- [
request_logger
]: Centralized request logging - [
performance
]: Performance metrics and profiling
Feature Flags
This crate supports several optional features:
openapi
: OpenAPI specification support (enabled by default)validation
: Request/response validation (enabled by default)templating
: Template expansion (enabled by default)chaos
: Chaos engineering features (enabled by default)proxy
: Proxy and hybrid mode (enabled by default)workspace
: Workspace management (enabled by default)
Examples
See the examples directory for complete working examples.
Related Crates
mockforge-http
: HTTP/REST mock servermockforge-grpc
: gRPC mock servermockforge-ws
: WebSocket mock servermockforge-graphql
: GraphQL mock servermockforge-plugin-core
: Plugin developmentmockforge-data
: Synthetic data generation