mockforge_sdk/lib.rs
1//! Pillars: [`DevX`]
2//!
3//! # `MockForge` SDK
4//!
5//! Developer SDK for embedding `MockForge` mock servers directly in unit and integration tests.
6//!
7//! ## Features
8//!
9//! - **Start/Stop Mock Servers**: Programmatically control mock server lifecycle
10//! - **Stub Responses**: Define mock responses with a fluent API
11//! - **Offline Mode**: Works without network dependencies
12//! - **Multi-Protocol**: HTTP, WebSocket, gRPC, GraphQL support
13//! - **Ergonomic API**: Builder pattern for easy configuration
14//!
15//! ## Quick Start
16//!
17//! ```rust,no_run
18//! use mockforge_sdk::MockServer;
19//! use serde_json::json;
20//!
21//! #[tokio::test]
22//! async fn test_user_api() {
23//! // Start a mock server
24//! let mut server = MockServer::new()
25//! .port(3000)
26//! .start()
27//! .await
28//! .expect("Failed to start server");
29//!
30//! // Stub a response
31//! server
32//! .stub_response("GET", "/api/users/{id}", json!({
33//! "id": "{{uuid}}",
34//! "name": "{{faker.name}}",
35//! "email": "{{faker.email}}"
36//! }))
37//! .await
38//! .expect("Failed to stub response");
39//!
40//! // Make requests to the mock server
41//! let client = reqwest::Client::new();
42//! let response = client
43//! .get("http://localhost:3000/api/users/123")
44//! .send()
45//! .await
46//! .expect("Failed to make request");
47//!
48//! assert_eq!(response.status(), 200);
49//!
50//! // Stop the server
51//! server.stop().await.expect("Failed to stop server");
52//! }
53//! ```
54
55pub mod admin;
56pub mod builder;
57pub mod conformance;
58pub mod error;
59pub mod ffi;
60pub mod server;
61pub mod stub;
62pub mod verification;
63
64pub use admin::{
65 AdminClient, MockConfig as AdminMockConfig, MockConfigBuilder, MockList,
66 MockResponse as AdminMockResponse, RequestMatchCriteria, ServerConfig as AdminServerConfig,
67 ServerStats,
68};
69pub use builder::MockServerBuilder;
70pub use conformance::{ConformanceClient, ConformanceRun, ConformanceRunRequest, RunStatus};
71pub use error::{Error, Result};
72pub use server::MockServer;
73pub use stub::{
74 DynamicResponseFn, DynamicStub, RequestContext, ResourceIdExtractConfig, ResponseStub,
75 StateMachineConfig, StateResponseOverride, StubBuilder, StubFaultInjectionConfig,
76};
77pub use verification::Verification;
78
79// Re-export commonly used types from mockforge-core
80pub use mockforge_core::{
81 Config, FailureConfig, LatencyProfile, OpenApiSpec, ProxyConfig, ServerConfig,
82};