diff --git a/imgs/25.png b/imgs/25.png new file mode 100644 index 0000000..81bb5a8 Binary files /dev/null and b/imgs/25.png differ diff --git a/package-lock.json b/package-lock.json index 1fca92a..197b4e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -63,6 +63,15 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" }, + "cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "requires": { + "object-assign": "^4", + "vary": "^1" + } + }, "debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -235,6 +244,16 @@ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" }, + "node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", diff --git a/package.json b/package.json index 944e450..9d13184 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,8 @@ }, "homepage": "https://github.com/code-differently/Pokedex-App#readme", "dependencies": { - "express": "^4.17.1" + "cors": "^2.8.5", + "express": "^4.17.1", + "node-fetch": "^2.6.1" } } diff --git a/rest/index.js b/rest/index.js index bba5463..1cff3c2 100644 --- a/rest/index.js +++ b/rest/index.js @@ -1,11 +1,36 @@ -const express = require('express') +const express = require('express'); +const fetch = require('node-fetch'); +const cors = require("cors"); + const app = express() -const port = 3000 +app.use(cors()) +const port = 4000 + + -app.get('/', (req, res) => { - res.send('Hello World!') +app.get('/all/:count', async (req, response) => { + const count = req.params.count; + fetch(`https://pokeapi.co/api/v2/pokemon?limit=${count}&offset=0`) + .then((res) => res.json()) + .then((allThePokemon) => { + const requestsToMake = allThePokemon.results.map(({ url }) => + fetch(url).then((res) => res.json()) + ); + return Promise.all(requestsToMake); + }) + .then(data => { + let responseResult = []; + for( let i = 0; i < count; i++){ + let responseObject = { id: data[i].id, name: data[i].name, type: data[i].types[0].type.name, image: data[i].sprites.front_default}; + responseResult.push(responseObject); + } + response.json(responseResult); + }) + .catch(err => console.error(err)); }) + + app.listen(port, () => { console.log(`Example app listening at http://localhost:${port}`) }) \ No newline at end of file diff --git a/web/index.html b/web/index.html index 1de928b..6a5ff05 100644 --- a/web/index.html +++ b/web/index.html @@ -1,11 +1,22 @@ -
- - -Hello Pokemon!
- - \ No newline at end of file + + + +