File: async.rs

package info (click to toggle)
rust-isahc 1.7.2%2Bds-20
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,044 kB
  • sloc: perl: 258; python: 148; makefile: 24; sh: 1
file content (16 lines) | stat: -rw-r--r-- 491 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! This example demonstrates the use of `send_async()` to make a request
//! asynchronously using the futures-based API.

use isahc::prelude::*;

fn main() -> Result<(), isahc::Error> {
    futures_lite::future::block_on(async {
        let mut response = isahc::get_async("http://example.org").await?;

        println!("Status: {}", response.status());
        println!("Headers:\n{:?}", response.headers());
        println!("Body: {}", response.text().await?);

        Ok(())
    })
}