Skip to content

feat: update timeout feature documentation #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//!
//! ```toml
//! [dependencies]
//! tinyget = { version = "1.0", features = ["https"] }
//! tinyget = { version = "1.1", features = ["https", "timeout"] }
//! ```
//!
//! Below is the list of all available features.
Expand All @@ -30,6 +30,29 @@
//! [`Request`](struct.Request.html) and
//! [`Response`](struct.Response.html) expose
//!
//! ## `timeout`
//!
//! This feature adds the ability to set a timeout for the request.
//! By default, a request has no timeout. You can change this in two ways:
//! - Use [`with_timeout`](struct.Request.html#method.with_timeout) on
//! your request to set the timeout per-request like so:
//! ```
//! tinyget::get("/").with_timeout(8).send();
//! ```
//! - Set the environment variable `TINYGET_TIMEOUT` to the desired
//! amount of seconds until timeout. Ie. if you have a program called
//! `foo` that uses tinyget, and you want all the requests made by that
//! program to timeout in 8 seconds, you launch the program like so:
//! ```text,ignore
//! $ TINYGET_TIMEOUT=8 ./foo
//! ```
//! Or add the following somewhere before the requests in the code.
//! ```
//! std::env::set_var("TINYGET_TIMEOUT", "8");
//! ```
//! If the timeout is set with `with_timeout`, the environment
//! variable will be ignored.
//!
//! # Examples
//!
//! This is a simple example of sending a GET request and printing out
Expand Down Expand Up @@ -100,7 +123,7 @@
//! To avoid timing out, or limit the request's response time, use
//! `with_timeout(n)` before `send()`. The given value is in seconds.
//!
//! NOTE: There is no timeout by default.
//! NOTE: To Use this feature, you need to enable the `timeout` feature.
//! ```no_run
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let response = tinyget::get("http://httpbin.org/delay/6")
Expand All @@ -109,27 +132,6 @@
//! println!("{}", response.as_str()?);
//! # Ok(()) }
//! ```
//!
//! # Timeouts
//! By default, a request has no timeout. You can change this in two ways:
//! - Use [`with_timeout`](struct.Request.html#method.with_timeout) on
//! your request to set the timeout per-request like so:
//! ```
//! tinyget::get("/").with_timeout(8).send();
//! ```
//! - Set the environment variable `TINYGET_TIMEOUT` to the desired
//! amount of seconds until timeout. Ie. if you have a program called
//! `foo` that uses tinyget, and you want all the requests made by that
//! program to timeout in 8 seconds, you launch the program like so:
//! ```text,ignore
//! $ TINYGET_TIMEOUT=8 ./foo
//! ```
//! Or add the following somewhere before the requests in the code.
//! ```
//! std::env::set_var("TINYGET_TIMEOUT", "8");
//! ```
//! If the timeout is set with `with_timeout`, the environment
//! variable will be ignored.

#![deny(missing_docs)]

Expand Down
Loading