pub struct HttpClient { /* private fields */ }Implementations§
Source§impl HttpClient
impl HttpClient
pub fn new(url: &str) -> Self
Sourcepub fn header(self, key: &str, value: &str) -> Self
pub fn header(self, key: &str, value: &str) -> Self
Examples found in repository?
examples/demo.rs (line 20)
4async fn main() {
5 // GET
6 let html = get("https://example.com")
7 .timeout(10)
8 .text()
9 .await
10 .unwrap();
11
12 println!("HTML:\n{}", html);
13
14 // POST JSON
15 let data = serde_json::json!({
16 "name": "Maestro"
17 });
18
19 let res = post("https://httpbin.org/post")
20 .header("Content-Type", "application/json")
21 .json(&data)
22 .await
23 .unwrap();
24
25 println!("POST response:\n{}", res);
26
27}Sourcepub fn timeout(self, secs: u64) -> Self
pub fn timeout(self, secs: u64) -> Self
Examples found in repository?
examples/demo.rs (line 7)
4async fn main() {
5 // GET
6 let html = get("https://example.com")
7 .timeout(10)
8 .text()
9 .await
10 .unwrap();
11
12 println!("HTML:\n{}", html);
13
14 // POST JSON
15 let data = serde_json::json!({
16 "name": "Maestro"
17 });
18
19 let res = post("https://httpbin.org/post")
20 .header("Content-Type", "application/json")
21 .json(&data)
22 .await
23 .unwrap();
24
25 println!("POST response:\n{}", res);
26
27}Sourcepub async fn text(self) -> Result<String, Error>
pub async fn text(self) -> Result<String, Error>
Examples found in repository?
examples/demo.rs (line 8)
4async fn main() {
5 // GET
6 let html = get("https://example.com")
7 .timeout(10)
8 .text()
9 .await
10 .unwrap();
11
12 println!("HTML:\n{}", html);
13
14 // POST JSON
15 let data = serde_json::json!({
16 "name": "Maestro"
17 });
18
19 let res = post("https://httpbin.org/post")
20 .header("Content-Type", "application/json")
21 .json(&data)
22 .await
23 .unwrap();
24
25 println!("POST response:\n{}", res);
26
27}Sourcepub async fn json<T: Serialize>(self, body: &T) -> Result<String, Error>
pub async fn json<T: Serialize>(self, body: &T) -> Result<String, Error>
Examples found in repository?
examples/demo.rs (line 21)
4async fn main() {
5 // GET
6 let html = get("https://example.com")
7 .timeout(10)
8 .text()
9 .await
10 .unwrap();
11
12 println!("HTML:\n{}", html);
13
14 // POST JSON
15 let data = serde_json::json!({
16 "name": "Maestro"
17 });
18
19 let res = post("https://httpbin.org/post")
20 .header("Content-Type", "application/json")
21 .json(&data)
22 .await
23 .unwrap();
24
25 println!("POST response:\n{}", res);
26
27}pub async fn fetch_json<T: DeserializeOwned>(self) -> Result<T, Error>
Auto Trait Implementations§
impl !RefUnwindSafe for HttpClient
impl !UnwindSafe for HttpClient
impl Freeze for HttpClient
impl Send for HttpClient
impl Sync for HttpClient
impl Unpin for HttpClient
impl UnsafeUnpin for HttpClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more