An API to fetch weather predictions:
- Receive a cURL request to the API (svc_weather_get.php) with a security token as a header value
svc_weather_get.php will:
- Test authorization of the api-token header value
- Log successful authorization
- Make a cURL request to api.weather.gov and display the weather prediction
Also included:
- A testing page to test a api-tokens
- A logging page to view errors
- A command-line file to directly make cURL requests to the API
- A JSON decoder to display JSON in human-friendly table format
This API was completed as part of a coding assessment, completed in 1 business day.
Specs for the Assessment:
---------------------------
1. Create an API endpoint with the following route: /api/weather/office/forecast
2. The /api/weather/office/forecast endpoint should consume/use the following URL to get the
weather forecast information
3. The /api/weather/office/forecast endpoint should consume/use the following URL to get the
weather forecast information: https://api.weather.gov/gridpoints/OKX/31,34/forecast
4. The /api/weather/office/forecast should be authenticated with tokens via an "Api-Token" header.
5. At least, the following tokens should be granted access:
QkgAVGXuebE9beJEV6iaMKRWf4eDAtALwi9FibuXvR37HYqEJuQKmVdv9eUEyx88
3o2fQgpAfxmQhPDsvhDThhyDMZZ7bRh7VcUGAn24UYJWnjVFDtnfZk77Go6NxB62
6. When the Api-Token header is not included, or an Api-Token that is not given access is used, the
API endpoint should return a "401" error.
7. When successfully authenticated the /api/weather/office/forecast should return a "200 OK" with
Content-Type: application/json where the response is a JSON collection of forecast periods,
where each period forecast has the following properties:
name
startTime
endTime
temperature
temperatureUnit
temperatureTrend
icon
shortForecast
8. The above tokens should be available in a "ApiToken" model that is persisted in a database table
with, at least, the following properties: Token, UsageCount, LastUsedOn; and every time the
/api/weather/office/forecast is successfully called with one of those tokens the model should be
updated by increasing the UsageCount and setting the LastUsedOn to the current date/time.
9. The assessment should have a readme file that enumerates the steps needed to run the
assessment