const API_VERSION = "0"; const API_URL = `/api/${API_VERSION}`; const TOKEN = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); async function get(url, params) { return await axios.get(url, { params: params, headers: { 'X-CSRF-Token': TOKEN } }).then(response => { return response.data; }).catch(error => { throw error; }); } async function query(endpoint, params) { return await get(`${API_URL}/${endpoint}`, params); } function getQuizz(lat, lng) { return query('game/quizz', { lat, lng }) .then(data => { return data; }).catch(error => { throw error; }); } function checkAnswer(speciesId) { return query(`game/check`, { species: speciesId }).then(data => { return data; }).catch(error => { throw error; }); } const client = { getQuizz, checkAnswer } export default client;