api_call update
This commit is contained in:
parent
f5b9fb28de
commit
91dd72c524
|
@ -1,3 +1,4 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
dist/
|
dist/
|
||||||
.parcel-cache/
|
.parcel-cache/
|
||||||
|
.parcel-cache/lock.mdb
|
||||||
|
|
|
@ -24,9 +24,6 @@
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="results">
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -1,18 +1,31 @@
|
||||||
import { api_call } from "./util";
|
import { api_call, API_URL } from "./util";
|
||||||
|
|
||||||
const planetes = document.getElementById("resultats");
|
const planetes = document.getElementById("resultats");
|
||||||
|
|
||||||
console.log('planet.js loaded');
|
console.log('planet.js loaded');
|
||||||
|
|
||||||
api_call("planets", console.log);
|
api_call(API_URL + "/planets", console.log);
|
||||||
|
|
||||||
|
|
||||||
function remplissage(prout){
|
function remplissage(results){
|
||||||
console.log(prout.results[0]);
|
|
||||||
|
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 =
|
planetes.innerHTML =
|
||||||
`<section class="resultat">
|
`<section class="resultat">
|
||||||
|
@ -25,4 +38,4 @@ function remplissage(prout){
|
||||||
</section>`;
|
</section>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
api_call("planets", remplissage);
|
// api_call(API_URL + "/planets", remplissage);
|
|
@ -1,14 +1,14 @@
|
||||||
console.log("util.js loaded");
|
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
|
* Envoie une requête GET à l'api swappi
|
||||||
* @param {string} endpoint l'endpoint à interroger (ex: planets)
|
* @param {string} endpoint l'endpoint à interroger (ex: planets)
|
||||||
* @param {function} callback La fonction qui traitera la réponse JSON en retour
|
* @param {function} callback La fonction qui traitera la réponse JSON en retour
|
||||||
*/
|
*/
|
||||||
export const api_call = (endpoint, callback) => {
|
export const api_call = (url, callback) => {
|
||||||
fetch(`${URL}/${endpoint}`)
|
fetch(url)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue