Skip to content
Snippets Groups Projects
APIService.tsx 486 B
Newer Older
Jacopo Gasparetto's avatar
Jacopo Gasparetto committed

class APIService {
  static isTokenValid(): boolean {
    return true;
  }

  static isAuthenticated = () => {
    return this.isTokenValid();
  }

  static async get(input: RequestInfo | URL, init?: RequestInit | undefined): Promise<any> {
    if (!APIService.isAuthenticated()) {
      return Promise.reject(new Error("Your are not autenticated"));
    }

    const response = await fetch("/api/v1/" + input, init);
Jacopo Gasparetto's avatar
Jacopo Gasparetto committed
    return await response.json();
Jacopo Gasparetto's avatar
Jacopo Gasparetto committed
  }
}

export default APIService;