parent
53496264d4
commit
fd47c40bf3
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"node-fetch": "^3.2.0",
|
||||||
|
"nodemon": "^2.0.15"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
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);
|
Loading…
Reference in new issue