mirror of
https://github.com/Noratrieb/mx-3.git
synced 2026-01-15 07:45:06 +01:00
not inital commit
This commit is contained in:
parent
3fb040df54
commit
0cd2146f3d
8 changed files with 3369 additions and 10 deletions
30
src/ApiClient.ts
Normal file
30
src/ApiClient.ts
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue