The Headlines web application allows users to view and save top news headlines for a chosen country. It utilizes the NewsApi to fetch the latest news data. The application supports both HTML and JSON distribution, and provides API endpoints for user registration, authentication, and managing saved articles.
Make sure you have the following software installed on your development machine:
- Docker
- Ruby (version 3.2.1)
- Ruby on Rails (version 7.0.4)
Follow the steps below to set up the development environment and run the Headlines application.
- Clone the repository:
git clone https://github.com/truetechcode/headline.git
- Navigate to the project directory:
cd headlines
- Update the environment variables:
Rename the .env.dev
file to .env
and replace the placeholder values with your actual environment variables:
# Get an API KEY for NEWSAPI from https://newsapi.org/account
NEWSAPI_KEY=sample_1234567890
DB_HOST=db
DB_PORT=5432
DB_NAME=headline_production
DB_USERNAME=headline
DB_PASSWORD=headline
- Build and run the Docker containers:
docker-compose up --build
- Run migrations:
docker-compose run web bundle exec rails db:migrate
- Start the Rails server:
docker-compose up
- Access the application:
Open a web browser and visit http://localhost:3000
to access the Headlines application.
The Headlines application provides the following API endpoints for user registration, authentication, and managing articles:
- Endpoint:
POST /api/users
- Payload: JSON
- Sample Payload:
{
"user": {
"name": "Test Example",
"email": "test@example.com",
"password": "password",
"country_code": "US"
}
}
- Endpoint:
POST /api/sessions
- Payload: JSON
- Sample Payload:
{
"session": {
"email": "test@example.com",
"password": "password"
}
}
- Endpoint:
DELETE /api/sessions/:id
- Endpoint:
GET /api/articles
- Endpoint:
POST /api/articles
- Payload: JSON
- Sample Payload:
{
"article": {
"source": "ABC News",
"author": "Aaron Katersky",
"title": "Judge sets January 2024 trial date for Sample News - ABC News",
"description": "Judge sets January 2024 trial date for Sample News.",
"url": "https://abcnews.go.com/US/judge-sets-january-2024-trial-date-jean-carrolls/story?id=100123378",
"url_to_image": "https://s.abcnews.com/images/Politics/sample_news_image_16x9_992.jpg",
"publish_at": "2023-06-16T04:20:39Z",
"content": "A judge has set an early 2024 trial date for sample"
}
}
- Endpoint:
DELETE /api/articles/:id
-
Implement Stimulus.js for Responsive Interactions:
- Integrate Stimulus.js into the Headlines application.
- Update the country select functionality to use Stimulus.js for a more responsive and dynamic user experience.
- Enhance the save and delete actions for headlines using Stimulus.js to perform the operations in-place without page refresh.
-
Background Job for NewsApi Call:
- Move the NewsApi call to a background job to offload the processing from the main request-response cycle.
- Configure the background job to run periodically or on-demand to update the headlines data from the NewsApi.
-
Replace has_secure_password with Devise for Authentication:
- Integrate Devise gem into the Headlines application.
- Implement token based API authentication strategy.
-
CI/CD Pipeline:
- Set up a Continuous Integration and Continuous Deployment (CI/CD) pipeline for the Headlines application.
-
Additional Enhancements:
- Implement pagination or infinite scrolling for the headlines index page to improve performance and user experience.
- Implement caching strategies to optimize API requests and improve overall application performance.
If you want to contribute to the Headlines application, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push your changes to your forked repository.
- Submit a pull request to the main repository.
The Headlines application is open-source and released under the MIT License.