Crates.io | atlas-http |
lib.rs | atlas-http |
version | 0.2.3 |
source | src |
created_at | 2024-02-10 09:59:59.016524 |
updated_at | 2024-06-27 13:53:38.845032 |
description | Simple, straight forward, easy to use HTTP client. |
homepage | https://apexpl.io/ |
repository | https://github.com/mdizak/rust-atlas-http |
max_upload_size | |
id | 1134843 |
size | 72,210 |
Clean, simplistic, easy to use HTTP client. Features:
use atlas_http::{HttpClient, HttpRequest, HttpBody, ProxyType};
// Simple GET request emulating web browser, utilizing cookies.txt as cookie jar
let mut http = HttpClient::builder()
.browser()
.cookie_jar("/path/to/cookies.txt")
.build_sync();
let res = http.get("https://www.google.com/").unwrap();
println!("Status: {}\nBody:\n\n{}", res.status_code(), res.body());
// POST request
let body = HttpBody::from_string("name=John Smith&email=john@example.com&country=CA");
let res = http.post("https://domain.com/register", &body).unwrap();
println!("Status: {}\nBody:\n\n{}", res.status_code(), res.body());
// Normal PSR-7 style POST, with upload file
let mut body = HttpBody::empty();
body.set_param("name", "John SMith");
body.set_param("email", "john@example.com");
body.upload_file("document", "/path/to/document.pdf");
let headers = vec![
"Site-User: myuser",
"Site-API-Key: abc12345"
];
let req = HttpRequest::new("POST", "https://example.com/form", &headers, &body);
let res = http.send(&req).unwrap();
println!("Status: {}\nBody:\n\n{}", res.status_code(), res.body());
// Download file
let res = http.download("https://example.com/path/to/file.tar.gz", "/home/me/file.tar.gz").unwrap();
if res.status_code() == 200 {
println!("GOt file!");
}
/// Send over SOCKS5 proxy at 192.168.0.24:1080
let mut http = HttpClient::builder()
.browser()
.cookie_jar("/path/to/cookies.txt")
.proxy("192.168.0.24", 1080)
.proxy_auth("myuser", "mypassword")
.proxy_type(ProxyType::SOCKS5)
.build_sync();
let res = http.get("https://some-domain.com/").unwrap();
println!("Status: {}\nBody:\n\n{}", res.status_code(), res.body());
/// Asynchronous example
let mut http = HttpClient::builder().browser().build_async();
let res = http.get("https://www.google.com/").await.unwrap();
println!("Status: {}\nBody:\n\n{}", res.status_code(), res.body());
// Async works exactly the same as syncronous. The only
// difference is you call ".build_async()" at the end of
// the builder instead of ".build_sync()". That's it.
If you need any assistance or software development done, contact me via e-mail at matt@apexpl.io.
Coming shortly, almost done.