A better Rust ATProto crate
at main 855 B view raw
1//! Example: Upload data using streaming request body 2 3use bytes::Bytes; 4use futures::stream; 5use jacquard_common::http_client::HttpClientExt; 6 7#[tokio::main] 8async fn main() -> Result<(), Box<dyn std::error::Error>> { 9 let client = reqwest::Client::new(); 10 11 // Create a stream of data chunks 12 let chunks = vec![ 13 Bytes::from("Hello, "), 14 Bytes::from("streaming "), 15 Bytes::from("world!"), 16 ]; 17 let body_stream = stream::iter(chunks); 18 19 // Build request and split into parts 20 let request = http::Request::builder() 21 .method(http::Method::POST) 22 .uri("https://httpbin.org/post") 23 .body(()) 24 .unwrap(); 25 26 let (parts, _) = request.into_parts(); 27 28 let response = client.send_http_bidirectional(parts, body_stream).await?; 29 println!("Status: {}", response.status()); 30 31 Ok(()) 32}