Skip to content

Commit

Permalink
add post_async example usage (#273)
Browse files Browse the repository at this point in the history
* add `post_async` example
  • Loading branch information
baoyachi authored Dec 15, 2020
1 parent 876cc03 commit 25513c6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
target
Cargo.lock
*.code-workspace

.idea/*
# Code coverage reports
cobertura.xml
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ structopt = "0.3"
tempfile = "3.1"
test-case = "1.0"
tracing-subscriber = "=0.2.12"
serde_json = "1"

[dev-dependencies.testserver]
path = "testserver"
Expand Down
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,30 @@ where
///
/// The request is executed using a shared [`HttpClient`] instance. See
/// [`HttpClient::post_async`] for details.
///
/// # Examples
///
/// ```no_run
/// use isahc::prelude::*;
///
/// async fn run() {
/// use futures_lite::AsyncReadExt;
/// let client = HttpClient::new().unwrap();
///
/// let mut response = client.post_async("https://httpbin.org/post", r#"{
/// "speed": "fast",
/// "cool_name": true
/// }"#).await.unwrap();
///
/// let mut body: Vec<u8> = vec![];
/// let mut reader = futures_lite::io::BufReader::new(response.body_mut());
/// reader.read_to_end(&mut body).await.unwrap();
///
/// let msg: serde_json::Value = serde_json::from_slice(&body).unwrap();
/// println!("{}", msg);
/// }
/// ```
///
pub fn post_async<U, B>(uri: U, body: B) -> ResponseFuture<'static>
where
http::Uri: TryFrom<U>,
Expand Down

0 comments on commit 25513c6

Please sign in to comment.