From 10baf7c051684e1e35b54cdc7b98517dd029e243 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sat, 12 Dec 2020 10:33:30 -0800 Subject: [PATCH] Clarify example from README. (#277) We should include the `fn main() -> Result` part, because people may not know they need the `-> Result` in order for `?` to work. Also, I replaced `Accept: text/html` with `Example-Header: header value`. My thinking is that if someone doesn't know they need to remove that Accept for non-HTML URLs, they might get unexpected results. --- README.md | 11 +++++++---- src/lib.rs | 14 +++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 45982ac..4797f06 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,13 @@ Version 2.0.0 was released recently and changed some APIs. See the [changelog] f In its simplest form, ureq looks like this: ```rust -let body: String = ureq::get("http://example.com") - .set("Accept", "text/html") - .call()? - .into_string()?; +fn main() -> Result<(), ureq::Error> { + let body: String = ureq::get("http://example.com") + .set("Example-Header", "header value") + .call()? + .into_string()?; + Ok(()) +} ``` For more involved tasks, you'll want to create an [Agent]. An Agent diff --git a/src/lib.rs b/src/lib.rs index 8fc44ab..26bf627 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,14 +23,14 @@ //! In its simplest form, ureq looks like this: //! //! ```rust -//! # fn main() -> Result<(), ureq::Error> { +//! fn main() -> Result<(), ureq::Error> { //! # ureq::is_test(true); -//! let body: String = ureq::get("http://example.com") -//! .set("Accept", "text/html") -//! .call()? -//! .into_string()?; -//! # Ok(()) -//! # } +//! let body: String = ureq::get("http://example.com") +//! .set("Example-Header", "header value") +//! .call()? +//! .into_string()?; +//! Ok(()) +//! } //! ``` //! //! For more involved tasks, you'll want to create an [Agent]. An Agent