EasyHttpMock is a powerful yet simple HTTP mock server designed specifically for testing HTTP clients. Built to work with any web server, it provides a clean, intuitive API for creating realistic mock endpoints that simulate real-world API behavior, making your testing workflow faster and more reliable.
- Testing-Focused: Purpose-built for HTTP client testing scenarios
- Lightning Fast: Powered by VeTiS for optimal performance
- Flexible Runtime: Choose between Tokio or Smol async runtimes
- Full Protocol Support: HTTP/1, HTTP/2, and HTTP/3 compatibility
- Secure Testing: Built-in TLS support for HTTPS endpoint testing
- Minimal Dependencies: Lightweight footprint for your test suite
Add EasyHttpMock to your Cargo.toml:
easyhttpmock = { version = "0.1.1", features = ["tokio-rt", "http1"] }Here's how simple it is to create a mock HTTP server for testing:
use easyhttpmock_vetis_tokio::{
EasyHttpMock,
config::EasyHttpMockConfig,
matchers::{method, path},
mock::{AsyncMatcherExt, Mock, StatusCodeExt, given},
vetis_adapter::VetisAdapter,
};
use http::{Method, StatusCode};
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let config = EasyHttpMockConfig::<VetisAdapter>::default();
let server = EasyHttpMock::new(config);
let mut server = match server {
Ok(server) => server,
Err(err) => {
panic!("Failed to create mock server: {}", err);
}
};
let mock = Mock::of(
given(method(Method::GET).and(path("/test"))).will_return(
StatusCode::OK
.respond()
.with_body(b"teste"),
),
);
server.register_mock(mock).await?;;
Ok(())
}- Unit Testing: Mock external APIs in your test suite
- Integration Testing: Test HTTP client behavior without real services
- Load Testing: Simulate API responses under various conditions
- Debugging: Reproduce API issues in a controlled environment
- Documentation: Create interactive API examples
- http1 - HTTP/1 protocol support
- http2 (default) - HTTP/2 protocol support
- http3 - HTTP/3 protocol support
- rust-tls (default) - TLS support
Base crate for easyhttpmock.
Adapter for vetis using smol runtime.
Adapter for vetis using tokio runtime.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Rogerio Pereira Araujo rogerio.araujo@gmail.com