Archi de base
This commit is contained in:
parent
5252705940
commit
966604bb1f
15 changed files with 77621 additions and 0 deletions
18
scripts/util.js
Normal file
18
scripts/util.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
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
|
||||
*/
|
||||
const api_call = (endpoint, callback) => {
|
||||
fetch(`${URL}/${endpoint}`)
|
||||
.then(response => {
|
||||
return response.json();
|
||||
})
|
||||
.then(jsonResp => {
|
||||
callback(jsonResp);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue