Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions simple-api-2/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}

body {
font-family: Arial, sans-serif;
background-color: #f5f7fa;
color: #333;
}

header {
background-color: #2c3e50;
color: white;
padding: 10px 20px;
}

nav {
display: flex;
justify-content: space-between;
align-items: center;
}

nav .logo {
font-size: 24px;
font-weight: bold;
}

nav ul {
display: flex;
list-style: none;
}

nav li {
margin: 0 15px;
font-size: 18px;
cursor: pointer;
display: flex;
align-items: center;
gap: 5px;
color: white;
transition: color 0.3s ease;
}

nav li:hover {
color: #ffcc00;
}

main {
text-align: center;
padding: 40px 20px;
}

main h1 {
font-size: 28px;
margin-bottom: 20px;
color: #2c3e50;
}

label {
display: block;
font-weight: bold;
margin: 15px 0;
}

p{
margin: 15px 0px
}

input[type="text"] {
width: 60%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 5px;
}

button {
background-color: #2980b9;
color: white;
margin-top: 10px;
padding: 10px 20px;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}

button:hover {
background-color: #1a5276;
}

ul {
list-style-type: disc;
margin: 20px auto;
padding: 0;
width: 80%;
text-align: left;
}
36 changes: 36 additions & 0 deletions simple-api-2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="This is where your description goes">
<meta name="keywords" content="one, two, three">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple API #2</title>
<!-- external CSS link -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<header>
<nav>
<div class="logo">
<i class="fas fa-landmark"></i> History API
</div>
<ul>
<li><i class="fas fa-home"></i> Home</li>
<li><i class="fas fa-book"></i> About</li>
<li><i class="fas fa-envelope"></i> Contact</li>
</ul>
</nav>
</header>
<main>
<section>
<h1>Search for a historical event and get some important facts!</h1>
<label for="location">Enter an event name:</label>
<p><em>Note:</em> Year: -45 = Year: 45 B.C.</p>
<input type="text" id="" placeholder="e.g., roman empire, ottoman empire, crusades" required>
<button type="button" name="button">Get History</button>
<ul id="factsUl"></ul>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
35 changes: 35 additions & 0 deletions simple-api-2/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
document.querySelector('button').addEventListener('click', getHistory)


function getHistory(){

const historyEvent = document.querySelector('input').value

const apiKey = '0tHj+S4vc1MB63o6bQVHRw==e2NEFPOhTwG3Em9S'
const url = `https://api.api-ninjas.com/v1/historicalevents?text=${historyEvent}`

fetch(url, {
headers: {
"X-Api-Key": apiKey // Include the API key in the Authorization header inside the fetch parameter
}
})
.then(res => res.json())
.then(data => {
console.log(data)

const factsList = document.querySelector('#factsUl');
//clear previous events
factsList.innerText = ''

// Iterate through the events and display all details
data.forEach((event) => {
const listItem = document.createElement('li');
listItem.innerText = `Year: ${event.year}, Month: ${event.month}, Day: ${event.day}, Event: ${event.event}`;
factsList.appendChild(listItem);
});

})
.catch(err =>{
console.log(`error ${err}`)
});
}