Skip to content

Commit

Permalink
Merge pull request #39 from fandok/feat/pokeapi
Browse files Browse the repository at this point in the history
add pokeapi page
  • Loading branch information
dishamodi0910 authored Oct 12, 2023
2 parents ea8bc19 + d41bf6a commit f50946e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Existing_API_Collection/PokeAPI/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />

<title>PokeAPI</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="description" content="PokeAPI page example" />

<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1>PokeAPI</h1>
<table id="pokemon">
<tr>
<th>Name</th>
<th>URL</th>
</tr>
</table>
<button id="loadmore" onclick="fetchData()">Load More</button>
<script src="index.js"></script>
</body>
</html>
30 changes: 30 additions & 0 deletions Existing_API_Collection/PokeAPI/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const API_URL = "https://pokeapi.co/api/v2/pokemon";

const addDataToPage = (value = []) => {
const pageData = value
.map(
(val) =>
`<tr><td>${val.name}</td><td><a href="${val.url}">${val.url}</a></td></tr>`
)
.join("");

const pokemonTag = document.getElementById("pokemon");
pokemonTag.innerHTML += pageData;
};

const fetchData = async () => {
let url = "";
if (document.getElementById("loadmore").value) {
url = document.getElementById("loadmore").value;
} else {
url = API_URL;
}

const response = await fetch(url);
const responseBody = await response.json();
addDataToPage(responseBody.results);

document.getElementById("loadmore").value = responseBody.next;
};

fetchData();
1 change: 1 addition & 0 deletions Existing_API_Collection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
|[Nasa API](./NasaAPI)|The APOD API provides access to the Astronomy Picture of the Day, which showcases a different astronomical image or photograph each day along with a brief explanation written by a professional astronomer.|
|[CryptoCurrencies API](./CryptoCurrenciesAPIs)| It is giving the data about total trading of the popular coins in 24 hrs.|
|[Giphy API](./GiphyAPI)|This API allows developers to integrate Giphy's vast library of GIFs into their own applications, websites, and services.|
|[PokeAPI](./PokeAPI/)| This API provides data regarding Pokemon and others related. |

0 comments on commit f50946e

Please sign in to comment.