Implement api client and add first test call to create api
This commit is contained in:
28
src/services/PerudoApi.ts
Normal file
28
src/services/PerudoApi.ts
Normal 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;
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user