Skip to content

A RESTful API backend that fetches news from multiple datasources and return builds an endpint to be consumed by clients

Notifications You must be signed in to change notification settings

HermanCeaser/laravel-news-api

Repository files navigation

Laravel News API (News Aggregation API)

News Aggregation API service built on Laravel

Branches

  • master - Branch off it. Must be stable.
  • dev - For Development

Configuration

Used for the API for News Aggregation, from NewsAPI, The Guardian & Newyork Times.

DB

  • DB_DATABASE - MySql DB Name. Defaults to laravel_new_api
  • DB_USERNAME - MySql DB Username.
  • DB_PASSWORD - MySql DB Password

NEWSAPI

  • NEWSAPI_KEY_DISABLED - The API key is given at NewsAPI.
  • NEWSAPI_TIMEOUT - Defaults to 15, if not set.
  • NEWSAPI_RETRY_TIMES - The number of times to retry fetching updated if failed on first request. Defaults to null, if not set
  • NEWSAPI_RETRY_SLEEP - The amount of time to wait between failed requests. Defaults to null, if not set

THE GUARDIAN NEWS

  • GUARDIANAPI_KEY - The API key is given at The Guardian.
  • GUARDIANAPI_TIMEOUT - Defaults to 15, if not set
  • GUARDIANAPI_RETRY_TIMES - The number of times to retry fetching updated if failed on first request. Defaults to null, if not set
  • GUARDIANAPI_RETRY_SLEEP - The amount of time to wait between failed requests. Defaults to null, if not set

THE NEWYORK TIMES

  • NEWYORKTIMESAPI_KEY - The API key is given at The Newyork Times
  • NEWYORKTIMESAPI_TIMEOUT - Defaults to 15, if not set
  • NEWYORKTIMESAPI_RETRY_TIMES - The amount of time to wait between failed requests. Defaults to null, if not set
  • NEWYORKTIMESAPI_RETRY_SLEEP - The amount of time to wait between failed requests. Defaults to null, if not set

Setup (Docker)

A docker-based infrastructure is available for development. If you wish to run directly on host, see Setup below.

  1. cp .env.example .env
  2. Set the database hostname in .env like DB_HOST=laravel-news-db
  3. docker compose --env-file .env -p laravel-news -f ./docker-compose.yml up -d
  4. docker exec -it laravel-news-php php artisan key:generate
  5. docker exec -it laravel-news-php php artisan migrate --seed
  • Nginx listens at your local IP address, port 8082, e.g. http://localhost:8082
  • Mysql container's port 3306 is mapped to the host.

Setup

  1. PHP8.2
  2. MySQL 8.0+
  3. Composer installed.
  4. cp .env.example .env
  5. Popuplate Your .env file with the keys and databases specifics as specified in the configuration section.
  6. composer install
  7. php artisan key:generate
  8. php artisan migrate
  9. php artisan serve

Usage

  • When you visit http://localhost:8082/api/news/top-headlines if you used docker or http://localhost:8000/api/news/top-headlines if you used local development, You should be able to see all the top-headlines

Author

Herman Ceaser

License

This Project is open sourced software licensed under the MIT license.

About

A RESTful API backend that fetches news from multiple datasources and return builds an endpint to be consumed by clients

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published