#request #lib #basic #proxy #header #http-post

minihttp

minihttp is a simple and lightweight http client lib for rust

10 releases

Uses old Rust 2015

0.1.9 Aug 22, 2017
0.1.8 Aug 19, 2017

#540 in HTTP client

25 downloads per month

MIT/Apache

22KB
365 lines

minihttp is a simple and lightweight http client lib for rust. only provide basic http client feature, more like python request. minihttp's aim is simple, easy to use, less dependent, smaller binary. Enjoy yourself...

#Example

send a get request

use minihttp::request::Request;

let mut http = Request::new("http://www.google.com").unwrap();
let res = http.get().send().unwrap();
println!("status code {}",res.status_code());
println!("reason {}",res.reason());
println!("body {}",res.text());
for (k,v) in res.headers(){
    println!("{}:{}",k,v);
}

send a post request

use minihttp::request::Request;

let mut http = Request::new("http://www.google.com").unwrap();
let res = http.post().body_str("hello").send().unwrap();
println!("status code {}",res.status_code());

custom headers

use std::collections::HashMap;
use minihttp::request::Request;

let mut http = Request::new("http://www.google.com").unwrap();
let mut headers = HashMap::new();
headers.insert("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36");
let res = http.headers(headers).send().unwrap();
println!("status code {}",res.status_code());

support https

use minihttp::request::Request;

let mut http = Request::new("https://www.google.com").unwrap();
let res = http.get().send().unwrap();
println!("status code {}",res.status_code());

support proxy

use minihttp::request::Request;

let mut http = Request::new("https://www.google.com").unwrap();
let res = http.proxy("https://127.0.0.1:1080").unwrap().get().send().unwrap();
println!("status code {}",res.status_code());

Dependencies

~0.1–8.5MB
~56K SLoC