PerudoClient/src/services/PerudoApi.ts

29 lines
904 B
TypeScript

import axios, { AxiosPromise, AxiosRequestConfig, AxiosResponse } from 'axios'
import {ApiObject, CreateGameObject} from "@/objects/objects";
export default class PerudoApi {
private static baseUrl = 'http://localhost:8000/'
private static objectInstance?: PerudoApi;
public static get instance(): PerudoApi {
if(typeof PerudoApi.objectInstance === 'undefined') {
PerudoApi.objectInstance = new PerudoApi();
}
return PerudoApi.objectInstance;
}
public createGame(name: string):Promise<CreateGameObject> {
return this.get<CreateGameObject>(PerudoApi.baseUrl + 'game/create?name=' + name)
.then((response: AxiosResponse<CreateGameObject>) => {
return response.data;
})
}
private get<T = any>(url: string, getParameters?: Record<string, any>) {
return axios.get(url).then((response: AxiosResponse<T>) => {
return response;
})
}
}