Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jayjamesjay committed Oct 13, 2024
1 parent 047845f commit fca1cc2
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 53 deletions.
95 changes: 47 additions & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# http_req

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

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

Expand Down
24 changes: 24 additions & 0 deletions examples/authentication.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use http_req::{
request::{Authentication, Request},
uri::Uri,
};

fn main() {
// Container for body of a response.
let mut body = Vec::new();
// URL of the website.
let uri = Uri::try_from("http://httpbin.org/basic-auth/foo/bar").unwrap();
// Authentication details: username and password.
let auth = Authentication::basic("foo", "bar");

// Sends a HTTP GET request and processes the response. Saves body of the response to `body` variable.
let res = Request::new(&uri)
.authentication(auth)
.send(&mut body)
.unwrap();

//Prints details about the response.
println!("Status: {} {}", res.status_code(), res.reason());
println!("Headers: {}", res.headers());
println!("{}", String::from_utf8_lossy(&body));
}
Loading

0 comments on commit fca1cc2

Please sign in to comment.