Skip to main content

sysreq/
lib.rs

1#![deny(missing_docs)]
2
3//! Simple, virtually-zero-dependencies HTTP client wrapping a system client.
4//!
5//! "Virtually-zero" means no unnecessary runtime dependencies. The only runtime dependency, other than `std`, is URL validation, which is required for security reasons.
6//!
7//! ## Supported Backends
8//!
9//! * wget
10//! * cURL
11//! * PowerShell (`Invoke-WebRequest`)
12//! # Usage
13//!
14//! In your `Cargo.toml`:
15//!
16//! ```toml
17//! [dependencies]
18//! sysreq = "0.1"
19//! ```
20//!
21//! In your code:
22//!
23//! ```rust
24//! let html = sysreq::get("https://www.rust-lang.org/").unwrap();
25//! println!("{}", String::from_utf8_lossy(&html));
26//! ```
27
28#[cfg(test)]
29mod tests;
30
31mod error;
32pub use error::Error;
33
34mod clients;
35use clients::{resolve::resolve, SystemHttpClientInterface};
36pub use clients::{
37	resolve::{http_client, installed},
38	supported_http_clients, SystemHttpClient,
39};
40
41mod url;
42use self::url::ValidUrl;
43
44mod request;
45pub use request::RequestBuilder;
46
47/// Perform a GET request to the given URL
48pub fn get(url: impl ValidUrl) -> Result<Vec<u8>, Error> {
49	Ok(resolve()?.get(url.validate()?, None)?.body)
50}