M client/src/api/user/login.rs => client/src/api/user/login.rs +5 -9
@@ 8,7 8,7 @@
use serde::{Deserialize, Serialize};
-use crate::NetworkingOptions;
+use crate::{NetworkingOptions, post_request};
use super::User;
@@ 41,14 41,10 @@ struct LoginPost {
}
pub fn login(no: &mut NetworkingOptions, email: &str, password: &str) -> LoginResponse {
- let res = no.req
- .post(&format!("{}/user/token", &no.api_address))
- .json(&LoginPost {
- email: email.to_string(),
- password: password.to_string(),
- })
- .send()
- .unwrap();
+ let res = post_request!(no, "/user/token", &LoginPost {
+ email: email.to_string(),
+ password: password.to_string(),
+ });
let tmp: LoginResponseJson = res.json().unwrap();
M client/src/api/user/register.rs => client/src/api/user/register.rs +6 -10
@@ 8,7 8,7 @@
use serde::Serialize;
-use crate::NetworkingOptions;
+use crate::{NetworkingOptions, post_request};
use super::User;
@@ 27,15 27,11 @@ pub fn register(
email: &str,
password: &str,
) -> RegisterResponse {
- let res = no.req
- .post(&format!("{}/user", &no.api_address))
- .json(&RegisterPost {
- username: username.to_string(),
- email: email.to_string(),
- password: password.to_string(),
- })
- .send()
- .unwrap();
+ let res = post_request!(no, "/user", &RegisterPost {
+ username: username.to_string(),
+ email: email.to_string(),
+ password: password.to_string(),
+ });
Ok(res.json().unwrap())
}