You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.8 KiB

import fetch from 'node-fetch';
var type;
var pokemon;
fetch('https://pokeapi.co/api/v2/type/')
.then(function (response) {
return response.json(); // transforme la réponse en json
})
.then(function (data) {
console.log(data); //affiche la réponse
type = data;
return fetch('https://pokeapi.co/api/v2/type/4/'); //type poison
})
.then(function (response) {
return response.json();
}).then(function (data) {
console.log(data.pokemon.slice(0,6)); // liste de 5 pokemon du type choisi
pokemon = data.pokemon.slice(0,6);
}).catch(function (error) {
console.log(error);
});
// async function start() {
// const response = await fetch('https://pokeapi.co/api/v2/type/');
// const data = await response.json();
// console.log(data);
// }
// start();
// function json_response(code, object, response) {
// response.statusCode = 200;
// response.setHeader('content-type', 'Application/json');
// response.end(JSON.stringify(object));
// }
// const server = http.createServer(function (request, response) {
// parsedUrl = url.parse(request.url, false);
// if(request.method === "POST") {
// console.log('POST');
// if(parsedUrl.query.param)
// {
// json_response(200,parsedUrl.query,response);
// }
// else
// {
// json_response(400,{error:"missing required param"},response);
// }
// }
// else if(request.method === "PUT") {
// console.log('PUT');
// json_response(200,{status : "where should I put it ?"},response);
// }
// else if(request.method === "DELETE") {
// console.log('DELETE');
// json_response(200,{status : "no delete available"},response);
// }
// else
// {
// json_response(200,{status : "active"},response);
// }
//
// });
// server.listen(8080);