This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const API_BASE_URL = 'https://dev.alfafrens.com//api/trpc/'; | |
async function fetchFromAPI(endpoint, queryParams = {}) { | |
const url = new URL(`${API_BASE_URL}/${endpoint}`); | |
Object.keys(queryParams).forEach(key => url.searchParams.append(key, queryParams[key])); | |
try { | |
const response = await fetch(url, { method: 'GET', headers: { 'Content-Type': 'application/json' } }); | |
if (!response.ok) throw new Error('AlfaFrens is sick response was not ok'); | |
const jsonResponse = await response.json(); | |
return jsonResponse.result ? jsonResponse.result.data : null; |
OlderNewer