1use tokio;
2
3pub async fn sleep(seconds: u64) {
4 tokio::time::sleep(tokio::time::Duration::from_secs(seconds)).await;
5}
6
7pub async fn sleep_micros(micros: u64) {
8 tokio::time::sleep(tokio::time::Duration::from_micros(micros)).await;
9}
10
11
12use reqwest;
13use serde_json;
14pub async fn get(api:&str)->Result<String, Box<dyn std::error::Error>> {
16 Ok(reqwest::Client::new().get(api)
17 .send()
18 .await?
19 .text()
20 .await?)
21}
22
23pub async fn post(api:&str, json:&serde_json::Value)->Result<String, Box<dyn std::error::Error>> {
25 Ok(reqwest::Client::new().post(api)
26 .json(&json)
27 .send()
28 .await?
29 .text()
30 .await?)
31}
32
33pub async fn form(api:&str, json:&serde_json::Value)->Result<String, Box<dyn std::error::Error>> {
34 Ok(reqwest::Client::new().post(api)
35 .form(&json)
36 .send()
37 .await?
38 .text()
39 .await?)
40}
41
42
43pub async fn form_with_headers(api:&str, json:&serde_json::Value, headers: &reqwest::header::HeaderMap)->Result<String, Box<dyn std::error::Error>> {
44 Ok(reqwest::Client::new().post(api)
45 .headers(headers.clone())
46 .form(&json)
47 .send()
48 .await?
49 .text()
50 .await?)
51}