ng-newsapi is the result of a code challenge presented in 2017. The result is a Laravel-powered API built to consume the NewsAPI service, store it locally, and allow querying
Project Specifications
- Pick one of these API’s: https://newsapi.org/ https://skyscanner.github.io/slate/#api-documentation
- Create an API to consume that API using Laravel
- Append each ‘record’ with two fields e.g NG_Description and NG_Review
- Output a list of records (edited)
Setup
- Clone the repository
- Run
composer install
- Copy the
.env-dist
file into.env
- Update
.env
with your database credentials and News API key - Run
php artisan migrate
to create the database structure - run
php artisan serve
to spin up a localhost instance
From here, you can go to the /api/sources
endpoint to pull in the news sources. Imported data is created in the local database, with additional NG_Description
and NG_Review
fields, and the results are output in JSON format.
Using the id
attribute, you can then consume individual sources by sending a request to /api/sources/{id}/articles
. Imported articles are also saved to the local database with additional fields, and results are output in JSON format.
API Documentation
Full API documentation is available in the ENDPOINTS.apib file, as well as online at docs.ngnewsapi.apiary.io.
Expansion Considerations
Given that this is a starter excersize, I didn't want to get carried away with items outside of scope. Were this a production application, however, next steps would include:
- Adding additional source data, including
urlsToLogo
andsortBysAvailable
data - Defaulting endpoints to look at local database rather than hitting the NewsAPI endpoint on every request
- Adding a
refresh
attribute to all requests to force NewsAPI data updates - Very likely adding integer primary keys to the
Source
model. I don't like using strings as primary keys, but that appears to be how NewsAPI's schema is designed. - Possibly extending the Guzzle class so we can include the NewsAPI API key on each request automatically, instead of keeping it in each controller method.
- Add exception handling for use of a bad API key or if NewsAPI is inaccessible.