not inital commit

This commit is contained in:
nora 2021-09-20 08:53:10 +02:00
parent 3fb040df54
commit 0cd2146f3d
8 changed files with 3369 additions and 10 deletions

30
src/ApiClient.ts Normal file
View file

@ -0,0 +1,30 @@
import axiosInstance from "./AxiosInstance";
import { Band } from "./Types";
export class ApiClient {
private readonly _cache: { [route: string]: any };
constructor() {
this._cache = {};
}
public async get<T>(route: string, force = false): Promise<T> {
if (!force && this._cache[route]) {
return this._cache[route];
}
const res = await axiosInstance.get(route);
const data = res.data.response;
if (res.status === 200) {
this._cache[route] = data;
}
return data;
}
public async searchBand(name: string): Promise<Band[]> {
const res = await this.get<any>(`/bands?query=${encodeURIComponent(name)}`);
return res.bands;
}
}
const client = new ApiClient();
export default client;