2021-10-18 13:24:38 +00:00
|
|
|
console.log("util.js loaded");
|
|
|
|
|
|
|
|
const URL = "https://swapi.dev/api";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Envoie un GET à l'api swappi
|
|
|
|
* @param {string} endpoint l'endpoint à interroger (ex: planets)
|
|
|
|
* @param {function} callback La fonction qui traitera la réponse JSON en retour
|
|
|
|
*/
|
2021-10-18 15:32:20 +00:00
|
|
|
export const api_call = (endpoint, callback) => {
|
2021-10-18 13:24:38 +00:00
|
|
|
fetch(`${URL}/${endpoint}`)
|
|
|
|
.then(response => {
|
|
|
|
return response.json();
|
|
|
|
})
|
|
|
|
.then(jsonResp => {
|
|
|
|
callback(jsonResp);
|
|
|
|
});
|
2021-10-18 15:32:20 +00:00
|
|
|
}
|
|
|
|
|