# `neto`
[](https://crates.io/crates/neto)
[](https://docs.rs/neto)
[](https://github.com/pas2rust/neto/blob/main/LICENSE)
**`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.
---
## โจ Features
- ๐๏ธ 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).
---
## โ๏ธ Installation
Add it to your `Cargo.toml`:
```bash
cargo add neto
```
## ๐ Usage
### Manual Client injection
Create an Http instance by passing a manually created reqwest::Client. Headers are stored but not applied automatically to the client.
```rs
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(())
}
```
### Automatic client creation with .config()
Build the Http struct without passing a client, then call .config() to create the reqwest::Client internally with all headers applied as default headers.
```rs
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(())
}
```
# โค๏ธ Donate
[](https://github.com/pas2rust/pas2rust/blob/main/pas-monero-donate.png)
[](https://github.com/pas2rust/pas2rust/blob/main/pas-bitcoin-donate.png)