neto
is a Rust crate providing a flexible HTTP client abstraction with a focus on builder patterns, header management, and easy configuration of reqwest::Client
. It supports both manual client injection and automatic client configuration with default headers.
- 🏗️ Fluent builder API for
Http
client with support for base URL, headers, and client. - ⚙️ Automatic creation of
reqwest::Client
with default headers via.config()
. - 🔐 Easy injection of authorization tokens and other headers.
- 🔄 Support for both manual
Client
passing and automatic client configuration. - 🚀 Async HTTP request helpers using
reqwest
. - 🧪 Comprehensive testing with real API calls (e.g., PokeAPI).
Add it to your Cargo.toml
:
cargo add neto
Create an Http instance by passing a manually created reqwest::Client. Headers are stored but not applied automatically to the client.
use neto::components::data::Http;
use reqwest::{Client, header::{HeaderValue, USER_AGENT}};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let headers = vec![(USER_AGENT, HeaderValue::from_static("neto-http-test/1.0"))];
let http = Http::new()
.base_url("https://pokeapi.co/api/v2")
.headers(headers)
.client(Client::new())
.build()
.expect("Should build Http");
let response = http.get("/pokemon/ditto", Vec::new()).await?;
assert!(response.status().is_success());
let json: serde_json::Value = response.json().await?;
println!("Name: {}", json["name"]);
Ok(())
}
Build the Http struct without passing a client, then call .config() to create the reqwest::Client internally with all headers applied as default headers.
use neto::components::data::Http;
use reqwest::header::{HeaderValue, USER_AGENT};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let headers = vec![(USER_AGENT, HeaderValue::from_static("neto-http-test/1.0"))];
let mut http = Http::new()
.base_url("https://pokeapi.co/api/v2")
.headers(headers)
.build()
.expect("Should build Http");
http.config().expect("Failed to configure Http");
let response = http.get("/pokemon/ditto", Vec::new()).await?;
assert!(response.status().is_success());
let json: serde_json::Value = response.json().await?;
println!("Name: {}", json["name"]);
Ok(())
}