diff --git a/.gitignore b/.gitignore index 09521a0..a098919 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules/ dist/ .parcel-cache/ +.parcel-cache/lock.mdb diff --git a/planets.html b/planets.html index 361cc20..8d1a3af 100644 --- a/planets.html +++ b/planets.html @@ -24,9 +24,6 @@ -
- -
\ No newline at end of file diff --git a/scripts/planets.js b/scripts/planets.js index 782d109..88ed73e 100644 --- a/scripts/planets.js +++ b/scripts/planets.js @@ -1,18 +1,31 @@ -import { api_call } from "./util"; +import { api_call, API_URL } from "./util"; const planetes = document.getElementById("resultats"); console.log('planet.js loaded'); -api_call("planets", console.log); +api_call(API_URL + "/planets", console.log); -function remplissage(prout){ - console.log(prout.results[0]); +function remplissage(results){ + + const previousUrl = results.previous; + const nextUrl = results.next; + const tabResults = results.results; + + for(resultPlanet of tabResults){ + const nom = resultPlanet.name; + const diametre = resultPlanet.diameter; + const climate = resultPlanet.climate; + const terrain = resultPlanet.terrain; + const population = resultPlanet.population; + + // const tabResidents = resultPLanet.residents; + // const tabResidents = call_api(`people/`); + const tabFilms = resultPLanet.films; + + } - api_call("films/1", (response) => { - console.log(response); - }); planetes.innerHTML = `
@@ -25,4 +38,4 @@ function remplissage(prout){
`; } -api_call("planets", remplissage); \ No newline at end of file +// api_call(API_URL + "/planets", remplissage); \ No newline at end of file diff --git a/scripts/util.js b/scripts/util.js index b24a777..e5c8ae1 100644 --- a/scripts/util.js +++ b/scripts/util.js @@ -1,14 +1,14 @@ console.log("util.js loaded"); -const URL = "https://swapi.dev/api"; +export const API_URL = "https://swapi.dev/api"; /** * Envoie une requête 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 */ -export const api_call = (endpoint, callback) => { - fetch(`${URL}/${endpoint}`) +export const api_call = (url, callback) => { + fetch(url) .then(response => { return response.json(); })