diff --git a/README.md b/README.md index 49c4188..c3470f8 100644 --- a/README.md +++ b/README.md @@ -6,18 +6,23 @@ ```rust #[macro_use] -extern create ureq; +extern crate ureq; -// sync post request of some json. -let resp = ureq::post("https://myapi.acme.com/ingest") - .set("X-My-Header", "Secret") - .send_json(json!({ - "name": "martin", - "rust": true - })); +fn main() { -// .ok() tells if response is 200-299. -assert!(resp.unwrap().ok()); + // sync post request of some json. + let resp = ureq::post("https://myapi.acme.com/ingest") + .set("X-My-Header", "Secret") + .send_json(json!({ + "name": "martin", + "rust": true + })); + + // .ok() tells if response is 200-299. + if resp.ok() { + // ... + } +} ``` ## Motivation diff --git a/src/lib.rs b/src/lib.rs index 050405c..cf28592 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,11 +5,31 @@ //! * Minimal dependency tree //! * Obvious API //! +//! ``` +//! #[macro_use] +//! extern crate ureq; +//! +//! fn main() { +//! // sync post request of some json. +//! let resp = ureq::post("https://myapi.acme.com/ingest") +//! .set("X-My-Header", "Secret") +//! .send_json(json!({ +//! "name": "martin", +//! "rust": true +//! })); +//! +//! // .ok() tells if response is 200-299. +//! if resp.ok() { +//! // .... +//! } +//! } +//! ``` +//! //! # Plain requests //! //! Most standard methods (GET, POST, PUT etc), are supported as functions from the //! top of the library ([`ureq::get`](fn.get.html), [`ureq::post`](fn.post.html), -//! [`ureq::put`](fn.out.html), etc). +//! [`ureq::put`](fn.put.html), etc). //! //! These top level http method functions create a [Request](struct.Request.html) instance //! which follows a build pattern. The builders are finished using diff --git a/src/response.rs b/src/response.rs index d79e896..47f1824 100644 --- a/src/response.rs +++ b/src/response.rs @@ -136,7 +136,8 @@ impl Response { /// Tells if this response is "synthetic". /// /// The [methods](struct.Request.html#method.call) [firing](struct.Request.html#method.send) - /// [off](struct.Request.html#method.send_string) [requests](struct.Request.html#method.send_json) + /// [off](struct.Request.html#method.send_string) + /// [requests](struct.Request.html#method.send_json) /// all return a `Response`; there is no rust style `Result`. /// /// Rather than exposing a custom error type through results, this library has opted @@ -150,7 +151,8 @@ impl Response { /// The specific mapping of error to code can be seen in the [`Error`](enum.Error.html) doc. /// /// However if the distinction is important, this method can be used to tell. Also see - /// [error()](struct.Response.html#method.synthetic_error) to see the actual underlying error. + /// [synthetic_error()](struct.Response.html#method.synthetic_error) + /// to see the actual underlying error. /// /// ``` /// // scheme that this library doesn't understand @@ -291,7 +293,7 @@ impl Response { /// /// ``` /// let resp = - /// ureq::get("https://raw.githubusercontent.com/algesten/ureq/master/src/test/hello_world.json").call(); + /// ureq::get("https://s3.amazonaws.com/foosrvr/hello_world.json").call(); /// /// let json = resp.into_json().unwrap(); ///