1
0
mirror of https://github.com/lexogrine/dota2-react-hud.git synced 2025-12-10 01:52:49 +01:00
Hubert Walczak 52e2cd949b
init
2021-07-10 20:25:28 +02:00

35 lines
909 B
JavaScript

async function apiV2(url, method = 'GET', body) {
const options = {
method,
headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
}
if (body) {
options.body = JSON.stringify(body)
}
let data = null;
return fetch(`/api/${url}`, options)
.then(res => {
data = res;
return res.json().catch(_e => data && data.status < 300)
});
}
const api = {
match: {
get: async () => apiV2(`match`),
getCurrent: async () => apiV2(`match/current`)
},
teams: {
getOne: async (id) => apiV2(`teams/${id}`),
get: () => apiV2(`teams`),
},
players: {
get: async () => apiV2(`players`),
getAvatarURLs: async (steamid) => apiV2(`players/avatar/steamid/${steamid}`)
},
tournaments: {
get: () => apiV2('tournament')
}
}
export { api };