rust_api_test/
api.rs

1use reqwest::{Client, Result};
2use serde_json::Value;
3use std::collections::HashMap;
4
5pub async fn get(url: &str) -> Result<Value> {
6    let response = Client::new().get(url).send().await?;
7    let json = response.json().await?;
8    Ok(json)
9}
10
11pub async fn post(url: &str, body: HashMap<&str, &str>) -> Result<Value> {
12    let response = Client::new().post(url).json(&body).send().await?;
13    let json = response.json().await?;
14    Ok(json)
15}
16
17pub async fn put(url: &str, body: HashMap<&str, &str>) -> Result<Value> {
18    let response = Client::new().put(url).json(&body).send().await?;
19    let json = response.json().await?;
20    Ok(json)
21}
22
23pub async fn delete(url: &str) -> Result<Value> {
24    let response = Client::new().delete(url).send().await?;
25    let json = response.json().await?;
26    Ok(json)
27}