aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-client/src/api_client.rs
diff options
context:
space:
mode:
authorConrad Ludgate <conradludgate@gmail.com>2021-12-08 13:37:49 +0000
committerGitHub <noreply@github.com>2021-12-08 13:37:49 +0000
commit4bdf4c40c292b681452c9499b9072b759073bf32 (patch)
tree1eddc50584485efbec2c1ab8e470844d25de12df /atuin-client/src/api_client.rs
parentRemove dev dep with wildcard (#224) (diff)
downloadatuin-4bdf4c40c292b681452c9499b9072b759073bf32.zip
feat: login/register no longer blocking (#216)
Diffstat (limited to 'atuin-client/src/api_client.rs')
-rw-r--r--atuin-client/src/api_client.rs18
1 files changed, 10 insertions, 8 deletions
diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs
index 24922836..3a4c859b 100644
--- a/atuin-client/src/api_client.rs
+++ b/atuin-client/src/api_client.rs
@@ -26,7 +26,7 @@ pub struct Client<'a> {
client: reqwest::Client,
}
-pub fn register(
+pub async fn register(
address: &str,
username: &str,
email: &str,
@@ -45,36 +45,38 @@ pub fn register(
}
let url = format!("{}/register", address);
- let client = reqwest::blocking::Client::new();
+ let client = reqwest::Client::new();
let resp = client
.post(url)
.header(USER_AGENT, APP_USER_AGENT)
.json(&map)
- .send()?;
+ .send()
+ .await?;
if !resp.status().is_success() {
return Err(eyre!("failed to register user"));
}
- let session = resp.json::<RegisterResponse>()?;
+ let session = resp.json::<RegisterResponse>().await?;
Ok(session)
}
-pub fn login(address: &str, req: LoginRequest) -> Result<LoginResponse<'static>> {
+pub async fn login(address: &str, req: LoginRequest<'_>) -> Result<LoginResponse<'static>> {
let url = format!("{}/login", address);
- let client = reqwest::blocking::Client::new();
+ let client = reqwest::Client::new();
let resp = client
.post(url)
.header(USER_AGENT, APP_USER_AGENT)
.json(&req)
- .send()?;
+ .send()
+ .await?;
if resp.status() != reqwest::StatusCode::OK {
return Err(eyre!("invalid login details"));
}
- let session = resp.json::<LoginResponse>()?;
+ let session = resp.json::<LoginResponse>().await?;
Ok(session)
}