Skip to main content

pawkit_net_http/native/
mod.rs

1use std::sync::LazyLock;
2
3use reqwest::Client;
4
5static HTTP_CLIENT: LazyLock<Client> = LazyLock::new(|| {
6    Client::builder()
7        .user_agent("PawKit")
8        .build()
9        .expect("Failed to build reqwest client")
10});
11
12pub async fn fetch_string(url: &str) -> Option<String> {
13    return HTTP_CLIENT.get(url).send().await.ok()?.text().await.ok();
14}
15
16pub async fn fetch_binary(url: &str) -> Option<Vec<u8>> {
17    return HTTP_CLIENT
18        .get(url)
19        .send()
20        .await
21        .ok()?
22        .bytes()
23        .await
24        .ok()
25        .map(|b| b.to_vec());
26}