-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- make the default no-client at all, backwards incompatible but better overall I think. - add reqwest 0.12 support
- Loading branch information
1 parent
cdee650
commit 1b59b85
Showing
11 changed files
with
105 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//! Shim reqwest into an unleash HTTP client | ||
// Copyright 2022 Cognite AS | ||
|
||
use async_trait::async_trait; | ||
use serde::{de::DeserializeOwned, Serialize}; | ||
|
||
use super::HttpClient; | ||
|
||
#[async_trait] | ||
impl HttpClient for reqwest_11::Client { | ||
type HeaderName = reqwest_11::header::HeaderName; | ||
type Error = reqwest_11::Error; | ||
type RequestBuilder = reqwest_11::RequestBuilder; | ||
|
||
fn build_header(name: &'static str) -> Result<Self::HeaderName, Self::Error> { | ||
Ok(Self::HeaderName::from_static(name)) | ||
} | ||
|
||
fn get(&self, uri: &str) -> Self::RequestBuilder { | ||
self.get(uri) | ||
} | ||
|
||
fn post(&self, uri: &str) -> Self::RequestBuilder { | ||
self.post(uri) | ||
} | ||
|
||
fn header( | ||
builder: Self::RequestBuilder, | ||
key: &Self::HeaderName, | ||
value: &str, | ||
) -> Self::RequestBuilder { | ||
builder.header(key.clone(), value) | ||
} | ||
|
||
async fn get_json<T: DeserializeOwned>(req: Self::RequestBuilder) -> Result<T, Self::Error> { | ||
req.send().await?.json::<T>().await | ||
} | ||
|
||
async fn post_json<T: Serialize + Sync>( | ||
req: Self::RequestBuilder, | ||
content: &T, | ||
) -> Result<bool, Self::Error> { | ||
let req = req.json(content); | ||
let res = req.send().await?; | ||
Ok(res.status().is_success()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters