mirror of
https://github.com/lexogrine/dota2-react-hud.git
synced 2025-12-10 10:02:50 +01:00
35 lines
909 B
JavaScript
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 }; |