Crate smolhttp

Source
Expand description

This project is a fork of the original minihttp that tries to improve the code and add more features, dont pushing aside the main purpose of the project thats is to be simple and lightweight.

§Example

§Sending a GET request

// Using the shortcut function
let content = smolhttp::get("https://www.rust-lang.org").unwrap().text();
println!("{content}");

// Using the Client
let content = smolhttp::Client::new("https://www.rust-lang.org").unwrap().get().send().unwrap().text();
println!("{content}");

§Examples

§Sending a POST request

// Using the shortcut funtion
let content = smolhttp::post("https://www.rust-lang.org").unwrap().text();
println!("{content}");

// Using the Client
let content = smolhttp::Client::new("https://www.rust-lang.org")
  .unwrap()
  .post()
  .send()
  .unwrap()
  .text();
println!("{content}");

§Using custom headers

use std::collections::HashMap;
let content = smolhttp::Client::new("https://www.rust-lang.org")
  .unwrap()
  .post()
  .headers(vec![("User-Agent".to_owned(), "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36".to_owned())])
  .send()
  .unwrap()
  .text();
println!("{content}");

§Using a proxy

let content = smolhttp::Client::new("http://www.google.com")
  .unwrap()
  .proxy("http://127.0.0.1:1080")
  .unwrap()
  .get()
  .send()
  .unwrap()
  .text();
println!("{content}");

Structs§

Client
http request object.
Proxy
proxy info object.

Enums§

HttpError
http basic error type

Functions§

delete
set Request DELETE method
get
set Request GET method
head
set Request HEAD method
options
set Request OPTIONS method
post
set Request POST method
put
set Request PUT method