Implement api client and add first test call to create api

This commit is contained in:
Tim
2021-07-05 01:34:57 +02:00
parent 775fa68909
commit 9b76a4e3ca
4 changed files with 55 additions and 4 deletions

28
src/services/PerudoApi.ts Normal file
View File

@@ -0,0 +1,28 @@
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;
})
}
}