-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96d0255
commit ffe9718
Showing
6 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# News Reader API | ||
|
||
Welcome to the News Reader API! This API allows you to fetch the latest news articles from various sources. Simply click the "Get News" button, and I'll provide you with the most recent headlines! | ||
|
||
## Features | ||
- **Fetch Latest News Articles:** Retrieve the most recent news articles from various sources. | ||
- **Simple User Interface:** Designed with simplicity in mind, making it easy to use. | ||
- **Error Handling:** Robust error handling ensures smooth API usage, providing meaningful error messages when necessary. | ||
|
||
## Technologies Used | ||
- HTML | ||
- CSS | ||
- JavaScript | ||
- API (for fetching news data) | ||
|
||
# API Integration | ||
This application uses an external API to fetch news data. The specific API endpoint and details can be found in the script.js file. | ||
|
||
## Installation | ||
To set up the News Reader API locally, follow these steps: | ||
|
||
1. Clone the repository. | ||
2. Navigate to the directory where the repository is cloned. | ||
3. Open the `index.html` file in a web browser. | ||
|
||
## Screenshots | ||
![Screenshot](assets/image.png) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>News Reader</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div class="news-container"> | ||
<h1>News Reader</h1> | ||
<button id="getNews">Get News</button> | ||
<div id="newsResult"></div> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Your JavaScript code | ||
document.getElementById('getNews').addEventListener('click', function() { | ||
const apiKey = '3887ca8399f947b4844a2c81ea570e40'; // Replace with your NewsAPI key | ||
const apiUrl = `https://newsapi.org/v2/top-headlines?country=us&apiKey=${apiKey}`; | ||
|
||
fetch(apiUrl) | ||
.then(response => response.json()) | ||
.then(data => { | ||
const newsResult = document.getElementById('newsResult'); | ||
newsResult.innerHTML = data.articles.map(article => ` | ||
<div class="news-item"> | ||
<h2>${article.title}</h2> | ||
<p>${article.description}</p> | ||
<a href="${article.url}" target="_blank">Read more</a> | ||
</div> | ||
`).join(''); | ||
}) | ||
.catch(error => { | ||
console.error('Error fetching the news:', error); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f0f0f0; /* Light grey */ | ||
margin: 0; | ||
padding: 0; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
} | ||
|
||
.news-container { | ||
background-color: #ffffff; /* White */ | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); | ||
border-radius: 10px; | ||
padding: 20px; | ||
width: 80%; | ||
max-width: 600px; | ||
text-align: center; | ||
} | ||
|
||
h1 { | ||
color: #333333; /* Dark grey */ | ||
font-size: 2em; | ||
margin-bottom: 20px; | ||
} | ||
|
||
button { | ||
background-color: #4CAF50; /* Green */ | ||
color: #ffffff; /* White */ | ||
border: none; | ||
padding: 10px 20px; | ||
border-radius: 5px; | ||
font-size: 1em; | ||
cursor: pointer; | ||
transition: background-color 0.3s ease; | ||
} | ||
|
||
button:hover { | ||
background-color: #45a049; /* Darker green on hover */ | ||
} | ||
|
||
#newsResult { | ||
margin-top: 20px; | ||
text-align: left; | ||
} | ||
|
||
.news-item { | ||
padding: 20px; | ||
border-bottom: 1px solid #dddddd; /* Lighter grey */ | ||
} | ||
|
||
.news-item:last-child { | ||
border-bottom: none; | ||
} | ||
|
||
.news-item h2 { | ||
font-size: 1.5em; | ||
margin: 0 0 10px 0; | ||
color: #007BFF; /* Blue */ | ||
} | ||
|
||
.news-item p { | ||
margin: 0; | ||
color: #666666; /* Grey */ | ||
font-size: 1em; | ||
} | ||
|
||
.news-item a { | ||
color: #4CAF50; /* Green */ | ||
text-decoration: none; | ||
font-weight: bold; | ||
} | ||
|
||
.news-item a:hover { | ||
text-decoration: underline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters