Skip to content

Commit fca1cc2

Browse files
committed
update docs
1 parent 047845f commit fca1cc2

File tree

4 files changed

+132
-53
lines changed

4 files changed

+132
-53
lines changed

Cargo.lock

Lines changed: 47 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# http_req
22

33
[![Rust](https://github.com/jayjamesjay/http_req/actions/workflows/rust.yml/badge.svg)](https://github.com/jayjamesjay/http_req/actions/workflows/rust.yml)
4-
[![Crates.io](https://img.shields.io/badge/crates.io-v0.12.0-orange.svg?longCache=true)](https://crates.io/crates/http_req)
5-
[![Docs.rs](https://docs.rs/http_req/badge.svg)](https://docs.rs/http_req/0.12.0/http_req/)
4+
[![Crates.io](https://img.shields.io/badge/crates.io-v0.13.0-orange.svg?longCache=true)](https://crates.io/crates/http_req)
5+
[![Docs.rs](https://docs.rs/http_req/badge.svg)](https://docs.rs/http_req/0.13.0/http_req/)
66

77
Simple and lightweight HTTP client with built-in HTTPS support.
88

examples/authentication.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use http_req::{
2+
request::{Authentication, Request},
3+
uri::Uri,
4+
};
5+
6+
fn main() {
7+
// Container for body of a response.
8+
let mut body = Vec::new();
9+
// URL of the website.
10+
let uri = Uri::try_from("http://httpbin.org/basic-auth/foo/bar").unwrap();
11+
// Authentication details: username and password.
12+
let auth = Authentication::basic("foo", "bar");
13+
14+
// Sends a HTTP GET request and processes the response. Saves body of the response to `body` variable.
15+
let res = Request::new(&uri)
16+
.authentication(auth)
17+
.send(&mut body)
18+
.unwrap();
19+
20+
//Prints details about the response.
21+
println!("Status: {} {}", res.status_code(), res.reason());
22+
println!("Headers: {}", res.headers());
23+
println!("{}", String::from_utf8_lossy(&body));
24+
}

0 commit comments

Comments
 (0)