From 403d2f65cefe0158e539e0e52fc72a41d73e88a9 Mon Sep 17 00:00:00 2001 From: Shubham Date: Mon, 8 Aug 2022 23:07:21 +0530 Subject: [PATCH 1/2] update README example to make it easier to plug and play --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b80b71e..c471f37 100644 --- a/README.md +++ b/README.md @@ -61,13 +61,25 @@ Whether it's a quick script, or a cross-platform SDK, Surf will make it work. ## Examples ```rust -let mut res = surf::get("https://httpbin.org/get").await?; -dbg!(res.body_string().await?); +use http_types; + +#[async_std::main] +async fn main() -> Result<(), http_types::Error> { + let mut res = surf::get("https://httpbin.org/get").await?; + dbg!(res.body_string().await?); + Ok(()) +} ``` It's also possible to skip the intermediate `Response`, and access the response type directly. ```rust -dbg!(surf::get("https://httpbin.org/get").recv_string().await?); +use http_types; + +#[async_std::main] +async fn main() -> Result<(), http_types::Error> { + dbg!(surf::get("https://httpbin.org/get").recv_string().await?); + Ok(()) +} ``` Both sending and receiving JSON is real easy too. From 72dfa4d9fc7aee507baecc1032f8fc2d545ee584 Mon Sep 17 00:00:00 2001 From: Shubham Date: Fri, 12 Aug 2022 08:49:54 +0530 Subject: [PATCH 2/2] replace [http_types::Error] with [surf::Error] and remove dependency from [http_types] --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c471f37..7d1e984 100644 --- a/README.md +++ b/README.md @@ -61,10 +61,8 @@ Whether it's a quick script, or a cross-platform SDK, Surf will make it work. ## Examples ```rust -use http_types; - #[async_std::main] -async fn main() -> Result<(), http_types::Error> { +async fn main() -> Result<(), surf::Error> { let mut res = surf::get("https://httpbin.org/get").await?; dbg!(res.body_string().await?); Ok(()) @@ -73,10 +71,8 @@ async fn main() -> Result<(), http_types::Error> { It's also possible to skip the intermediate `Response`, and access the response type directly. ```rust -use http_types; - #[async_std::main] -async fn main() -> Result<(), http_types::Error> { +async fn main() -> Result<(), surf::Error> { dbg!(surf::get("https://httpbin.org/get").recv_string().await?); Ok(()) }