use std::collections::HashMap;
#[cfg(feature = "async")]
use macro_rules_attribute::apply;
use crate::ApiRequest;
use crate::JsonParser;
use crate::endpoints::EndpointUriBuilder;
fn httpbin_get_request(arg: &str, value: &str) -> ApiRequest<JsonParser<HttpBinGetResponse>> {
EndpointUriBuilder::new()
.https()
.set_authority("httpbin.org")
.set_path("/get")
.add_parameter(arg, value)
.into_api_request(crate::HTTPVerb::Get, JsonParser::default())
.unwrap()
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
struct HttpBinGetResponse {
args: HashMap<String, String>,
}
#[test]
#[cfg(feature = "sync")]
fn test_get_query() {
use crate::ApiClient;
let client = ApiClient::builder().build();
let res = httpbin_get_request("hello", "world")
.send(&client)
.unwrap()
.parse()
.unwrap();
assert_eq!(res.args.get("hello"), Some(&"world".to_string()))
}
#[cfg(feature = "async")]
#[apply(smol_macros::test!)]
async fn test_get_query_async() {
use crate::ApiClient;
let client = ApiClient::builder().build();
let res = httpbin_get_request("hello", "world")
.send_async(&client)
.await
.unwrap()
.parse()
.unwrap();
assert_eq!(res.args.get("hello"), Some(&"world".to_string()))
}