This application utilizes the News API to retrieve top headlines based on the user's specified country and the user category. The News API is a convenient HTTP REST API for accessing real-time articles from various sources on the web.
To use this application, you need to obtain an API key from News API. Follow these steps:
- Sign up for a free account on the News API website.
- Once logged in, navigate to your dashboard to find your API key.
- Copy your API key and replace the placeholder in the
URL
variable within themainSearch
class.
https://newsapi.org/v2/everything?q=technology&apiKey=your-api-key
- Compile: Compile the project using your Java IDE or command line.
- Run Application: Execute the
mainSearch
class. - Input Country: Enter the desired country when prompted.
- Select Topic: Choose a topic from the provided categories.
- View Results: The application will display the top headlines based on your selections.
Class | Description |
---|---|
mainSearch.java |
Contains the main class responsible for user interaction and API call initiation. |
NewsApiClient.java |
Implements API client functionality for making requests to the News API. |
Article.java |
Defines the structure of an article retrieved from the API. |
ApiResponseDto.java |
Represents the structure of the API response, including status, total results, and a list of articles. |
The ArticleDTO
class encapsulates information about a single news article.
Field | Description |
---|---|
title |
The title of the article. |
description |
A brief description or summary of the article. |
url |
The URL link to access the full article. |
urlToImage |
The URL link to the image associated with the article. |
publishedAt |
The date and time when the article was published. |
content |
The main textual content of the article. |
The ApiResponseDTO
class represents the structure of the response obtained from the News API.
Field | Description |
---|---|
status |
The status of the API request (e.g., "ok" for successful requests). |
totalResults |
The total number of articles matching the query parameters. |
articles |
A list of ArticleDTO objects containing details of individual articles. |
- Google Gson: Used for JSON serialization and deserialization.
- Java HttpClient: Utilized for making HTTP requests to the News API.
This application offers a convenient way to access real-time news articles based on user-defined parameters. By integrating the News API, it provides a seamless experience for retrieving relevant news content.
For further details on the News API, refer to the official documentation provided by News API.