use model::{AccessTokenString, RefreshTokenString}; use seed::prelude::*; pub async fn fetch_products() -> fetch::Result { Request::new("/api/v1/products") .method(Method::Get) .fetch() .await? .check_status()? .json() .await } pub async fn fetch_product(product_id: model::ProductId) -> fetch::Result { Request::new(format!("/api/v1/product/{}", product_id)) .method(Method::Get) .fetch() .await? .check_status()? .json() .await } pub async fn fetch_me(access_token: AccessTokenString) -> fetch::Result { Request::new("/api/v1/me") .header(fetch::Header::bearer(access_token.as_str())) .method(Method::Get) .fetch() .await? .check_status()? .json() .await } pub async fn sign_in(input: model::api::SignInInput) -> fetch::Result { Request::new("/api/v1/sign-in") .method(Method::Post) .json(&input)? .fetch() .await? .check_status()? .json() .await } pub async fn verify_token(access_token: AccessTokenString) -> fetch::Result { Request::new("/api/v1/token/verify") .method(Method::Post) .header(fetch::Header::bearer(access_token.as_str())) .fetch() .await? .check_status()? .json() .await } pub async fn refresh_token( access_token: RefreshTokenString, ) -> fetch::Result { Request::new("/api/v1/token/refresh") .method(Method::Post) .header(fetch::Header::bearer(access_token.as_str())) .fetch() .await? .check_status()? .json() .await }