Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .commitlintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules:
description-empty: # Description shouldn't be empty
level: warning
subject-empty: # Subject line should exist
level: error
type-empty: # Type must not be empty
level: error
3 changes: 3 additions & 0 deletions .samoyed/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

commitlint --edit $1
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "easyhttpmock"
version = "0.1.3-beta.1"
version = "0.1.3-beta.7"
edition = "2021"
authors = ["Rogerio Araújo <rogerio.araujo@gmail.com>"]
repository = "https://github.com/ararog/easyhttpmock"
Expand All @@ -12,14 +12,19 @@ keywords = ["http", "mock", "testing"]
publish = true
rust-version = "1.75.0"

[package.metadata.docs.rs]
all-features = true

[features]
default = ["tokio-rt", "http2", "tokio-rust-tls"]

tokio-rt = ["vetis/tokio-rt", "vetis/__deboa_tokio"]
smol-rt = ["vetis/smol-rt", "vetis/__deboa_smol"]
#compio-rt = ["vetis/compio-rt"]

tokio-rust-tls = ["vetis/tokio-rust-tls"]
smol-rust-tls = ["vetis/smol-rust-tls"]
#compio-rust-tls = ["vetis/compio-rust-tls"]

http1 = ["vetis/http1"]
http2 = ["vetis/http2"]
Expand Down
54 changes: 29 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# EasyHttpMock

[![Crates.io downloads](https://img.shields.io/crates/d/easyhttpmock)](https://crates.io/crates/easyhttpmock) [![crates.io](https://img.shields.io/crates/v/easyhttpmock?style=flat-square)](https://crates.io/crates/easyhttpmock) [![Build Status](https://github.com/ararog/easyhttpmock/actions/workflows/rust.yml/badge.svg?event=push)](https://github.com/ararog/easyhttpmock/actions/workflows/rust.yml) ![Crates.io MSRV](https://img.shields.io/crates/msrv/easyhttpmock) [![Documentation](https://docs.rs/easyhttpmock/badge.svg)](https://docs.rs/easyhttpmock/latest/easyhttpmock) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ararog/easyhttpmock/blob/main/LICENSE.md) [![codecov](https://codecov.io/gh/ararog/easyhttpmock/graph/badge.svg?token=T0HSBAPVSI)](https://codecov.io/gh/ararog/easyhttpmock)


**The effortless HTTP mock server for seamless API testing**

**EasyHttpMock** is a powerful yet simple HTTP mock server designed specifically for testing HTTP clients. Built on top of [VeTiS](https://github.com/ararog/vetis), 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.
Expand All @@ -26,25 +29,25 @@ easyhttpmock = { version = "0.1.1", features = ["tokio-rt", "http2", "tokio-rust
Here's how simple it is to create a mock HTTP server for testing:

```rust
use bytes::Bytes;
use http::StatusCode;
use http_body_util::Full;
use hyper::Response;

use easyhttpmock::{
config::EasyHttpMockConfig,
server::{adapters::vetis_adapter::VetisServerAdapter, PortGenerator},
EasyHttpMock,
};

use deboa::{cert::ContentEncoding, request::DeboaRequest, Client};

use vetis::{
config::EasyHttpMockConfig,
server::{
config::{SecurityConfig, ServerConfig},
PortGenerator,
adapters::vetis_adapter::{VetisAdapter, VetisAdapterConfig},
},
};

use deboa::{
Client,
cert::{Certificate, ContentEncoding},
request::DeboaRequest,
};

use vetis::Response;

pub const CA_CERT: &[u8] = include_bytes!("../certs/ca.der");
pub const CA_CERT_PEM: &[u8] = include_bytes!("../certs/ca.crt");

Expand All @@ -53,25 +56,25 @@ pub const SERVER_KEY: &[u8] = include_bytes!("../certs/server.key.der");

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let tls_config = SecurityConfig::builder()
.cert(SERVER_CERT.to_vec())
.key(SERVER_KEY.to_vec())
.build();

let vetis_config = ServerConfig::builder()
.security(tls_config)
let vetis_adapter_config = VetisAdapterConfig::builder()
.interface("0.0.0.0")
.with_random_port()
.cert(Some(SERVER_CERT.to_vec()))
.key(Some(SERVER_KEY.to_vec()))
.ca(Some(CA_CERT.to_vec()))
.build();

let config = EasyHttpMockConfig::<VetisServerAdapter>::builder()
.server_config(vetis_config)
let config = EasyHttpMockConfig::<VetisAdapter>::builder()
.server_config(vetis_adapter_config)
.build();

let mut server = EasyHttpMock::new(config);
let mut server = EasyHttpMock::new(config)?;
#[allow(unused_must_use)]
let result = server
.start(|_| async move {
Ok(Response::new(Full::new(Bytes::from("Hello World"))))
Ok(Response::builder()
.status(StatusCode::OK)
.text("Hello World"))
})
.await;

Expand All @@ -80,10 +83,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
});

let client = Client::builder()
.certificate(deboa::cert::Certificate::from_slice(CA_CERT, ContentEncoding::DER))
.certificate(Certificate::from_slice(CA_CERT, ContentEncoding::DER))
.build();

let request = DeboaRequest::get(server.url("/anything"))?.build()?;
let url = server.url("/anything");
let request = DeboaRequest::get(url)?.build()?;

let response = client
.execute(request)
Expand All @@ -96,7 +100,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
server
.stop()
.await?;

Ok(())
}
```
Expand Down
47 changes: 21 additions & 26 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ permalink: /
<h1><b>EasyHttpMock</b></h1>
</div>

[![crates.io](https://img.shields.io/crates/v/easyhttpmock?style=flat-square)](https://crates.io/crates/easyhttpmock)
[![Build Status](https://github.com/ararog/easyhttpmock/actions/workflows/rust.yml/badge.svg?event=push)](https://github.com/ararog/easyhttpmock/actions/workflows/rust.yml)
[![Documentation](https://docs.rs/easyhttpmock/badge.svg)](https://docs.rs/easyhttpmock/latest/easyhttpmock)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Crates.io downloads](https://img.shields.io/crates/d/easyhttpmock)](https://crates.io/crates/easyhttpmock) [![crates.io](https://img.shields.io/crates/v/easyhttpmock?style=flat-square)](https://crates.io/crates/easyhttpmock) [![Build Status](https://github.com/ararog/easyhttpmock/actions/workflows/rust.yml/badge.svg?event=push)](https://github.com/ararog/easyhttpmock/actions/workflows/rust.yml) ![Crates.io MSRV](https://img.shields.io/crates/msrv/easyhttpmock) [![Documentation](https://docs.rs/easyhttpmock/badge.svg)](https://docs.rs/easyhttpmock/latest/easyhttpmock) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ararog/easyhttpmock/blob/main/LICENSE.md) [![codecov](https://codecov.io/gh/ararog/easyhttpmock/graph/badge.svg?token=T0HSBAPVSI)](https://codecov.io/gh/ararog/easyhttpmock)

**EasyHttpMock** is a powerful yet simple HTTP mock server designed specifically for testing HTTP clients. Built on top of [VeTiS](https://github.com/ararog/vetis), 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.

Expand All @@ -37,25 +34,25 @@ easyhttpmock = { version = "0.0.9" }
Basic usage:

```rust
use bytes::Bytes;
use http::StatusCode;
use http_body_util::Full;
use hyper::Response;

use easyhttpmock::{
config::EasyHttpMockConfig,
server::{adapters::vetis_adapter::VetisServerAdapter, PortGenerator},
EasyHttpMock,
};

use deboa::{cert::ContentEncoding, request::DeboaRequest, Client};

use vetis::{
config::EasyHttpMockConfig,
server::{
config::{SecurityConfig, ServerConfig},
PortGenerator,
adapters::vetis_adapter::{VetisAdapter, VetisAdapterConfig},
},
};

use deboa::{
Client,
cert::{Certificate, ContentEncoding},
request::DeboaRequest,
};

use vetis::Response;

pub const CA_CERT: &[u8] = include_bytes!("../certs/ca.der");
pub const CA_CERT_PEM: &[u8] = include_bytes!("../certs/ca.crt");

Expand All @@ -64,22 +61,19 @@ pub const SERVER_KEY: &[u8] = include_bytes!("../certs/server.key.der");

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let tls_config = SecurityConfig::builder()
.cert(SERVER_CERT.to_vec())
.key(SERVER_KEY.to_vec())
.build();

let vetis_config = ServerConfig::builder()
.security(tls_config)
let vetis_adapter_config = VetisAdapterConfig::builder()
.interface("0.0.0.0")
.with_random_port()
.cert(Some(SERVER_CERT.to_vec()))
.key(Some(SERVER_KEY.to_vec()))
.ca(Some(CA_CERT.to_vec()))
.build();

let config = EasyHttpMockConfig::<VetisServerAdapter>::builder()
.server_config(vetis_config)
let config = EasyHttpMockConfig::<VetisAdapter>::builder()
.server_config(vetis_adapter_config)
.build();

let mut server = EasyHttpMock::new(config);
#[allow(unused_must_use)]
let mut server = EasyHttpMock::new(config)?;
let result = server
.start(|_| async move {
Ok(Response::new(Full::new(Bytes::from("Hello World"))))
Expand Down Expand Up @@ -109,6 +103,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.await?;

Ok(())
}
```

## Examples
Expand Down
56 changes: 27 additions & 29 deletions docs/llms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
easyhttpmock = { version = "0.0.1", features = ["http1", "tokio-rt", "tokio-rust-tls"] }
```

## 💡 Usage Example
## Usage Example

```rust
use bytes::Bytes;
use http::StatusCode;
use http_body_util::Full;
use hyper::Response;

use easyhttpmock::{
config::EasyHttpMockConfig,
server::{adapters::vetis_adapter::VetisServerAdapter, PortGenerator},
EasyHttpMock,
};

use deboa::{cert::ContentEncoding, request::DeboaRequest, Client};

use vetis::{
config::EasyHttpMockConfig,
server::{
config::{SecurityConfig, ServerConfig},
PortGenerator,
adapters::vetis_adapter::{VetisAdapter, VetisAdapterConfig},
},
};

use deboa::{
Client,
cert::{Certificate, ContentEncoding},
request::DeboaRequest,
};

use vetis::Response;

pub const CA_CERT: &[u8] = include_bytes!("../certs/ca.der");
pub const CA_CERT_PEM: &[u8] = include_bytes!("../certs/ca.crt");

Expand All @@ -39,22 +39,19 @@ pub const SERVER_KEY: &[u8] = include_bytes!("../certs/server.key.der");

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let tls_config = SecurityConfig::builder()
.cert(SERVER_CERT.to_vec())
.key(SERVER_KEY.to_vec())
.build();

let vetis_config = ServerConfig::builder()
.security(tls_config)
let vetis_adapter_config = VetisAdapterConfig::builder()
.interface("0.0.0.0")
.with_random_port()
.cert(Some(SERVER_CERT.to_vec()))
.key(Some(SERVER_KEY.to_vec()))
.ca(Some(CA_CERT.to_vec()))
.build();

let config = EasyHttpMockConfig::<VetisServerAdapter>::builder()
.server_config(vetis_config)
let config = EasyHttpMockConfig::<VetisAdapter>::builder()
.server_config(vetis_adapter_config)
.build();

let mut server = EasyHttpMock::new(config);
#[allow(unused_must_use)]
let mut server = EasyHttpMock::new(config)?;
let result = server
.start(|_| async move {
Ok(Response::new(Full::new(Bytes::from("Hello World"))))
Expand Down Expand Up @@ -84,16 +81,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.await?;

Ok(())
}
```

## Features

- **🎯 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
- ** 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

## Blog Posts

Expand Down
3 changes: 0 additions & 3 deletions samoyed.toml

This file was deleted.

Loading