Expand description
§EasyHttpMock Vetis Tokio
This crate provides the core functionality for creating HTTP mock servers using the Tokio runtime.
§Quick Start
Add EasyHttpMock Vetis Tokio to your Cargo.toml:
easyhttpmock-vetis-tokio = { version = "0.1.0-beta.3", features = ["http1", "rust-tls"] }§Usage Example
Here’s how simple it is to create a web server with VeTiS:
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(())
}§License
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.
§Author
Rogerio Pereira Araujo rogerio.araujo@gmail.com
Modules§
- config
- Configuration module
- errors
- Error module
- matchers
- Matchers module
- mock
- Mock module
- server
- Server module
- vetis_
adapter - Vetis tokio adapter module
Structs§
- Easy
Http Mock - Create a mock using a specific server implementation
Enums§
- Protocol
- Supported HTTP protocols.
Type Aliases§
- Http
Mock Result - Result type for HTTP mock operations