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.
This commit is contained in:
Jacob Hoffman-Andrews
2020-12-12 10:33:30 -08:00
committed by GitHub
parent 1448969dd7
commit 10baf7c051
2 changed files with 14 additions and 11 deletions

View File

@@ -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: In its simplest form, ureq looks like this:
```rust ```rust
let body: String = ureq::get("http://example.com") fn main() -> Result<(), ureq::Error> {
.set("Accept", "text/html") let body: String = ureq::get("http://example.com")
.call()? .set("Example-Header", "header value")
.into_string()?; .call()?
.into_string()?;
Ok(())
}
``` ```
For more involved tasks, you'll want to create an [Agent]. An Agent For more involved tasks, you'll want to create an [Agent]. An Agent

View File

@@ -23,14 +23,14 @@
//! In its simplest form, ureq looks like this: //! In its simplest form, ureq looks like this:
//! //!
//! ```rust //! ```rust
//! # fn main() -> Result<(), ureq::Error> { //! fn main() -> Result<(), ureq::Error> {
//! # ureq::is_test(true); //! # ureq::is_test(true);
//! let body: String = ureq::get("http://example.com") //! let body: String = ureq::get("http://example.com")
//! .set("Accept", "text/html") //! .set("Example-Header", "header value")
//! .call()? //! .call()?
//! .into_string()?; //! .into_string()?;
//! # Ok(()) //! Ok(())
//! # } //! }
//! ``` //! ```
//! //!
//! For more involved tasks, you'll want to create an [Agent]. An Agent //! For more involved tasks, you'll want to create an [Agent]. An Agent