A laravel package to interface with the Apixu API
This package adds a facade and a dependency injectable class you can use to make easy calls to the api, (*1)
You can install the package via composer:, (*2)
``` bash composer require rjvandoesburg/laravel-apixu-client, (*3)
You must install the following service provider: ```php // config/app.php 'providers' => [ ... Rjvandoesburg\Apixu\ApixuServiceProvider::class, ... ];
This package requires an API key that can be stored in the .env
file. You can get your key here: https://www.apixu.com/
The following settings are available for your .env
file:, (*4)
APIXU_KEY={your-key-here} APIXU_URL=https://api.apixu.com/v1 APIXU_CACHE_LENGTH=30
The cache length is how long before new data is fetched from the server, this because you might want to limit the API calls, (*5)
These settings are set in a config file that you can edit yourself, should you desire to do so. Execute the following command to get the config file, (*6)
php artisan vendor:publish --provider="Rjvandoesburg\Apixu\ApixuServiceProvider"
A file named apixu.php
will be created in the config directory., (*7)
The API has 4 endpoint * Current * Forecast * History * Search, (*8)
Each request needs certain parameters, read more about those here, (*9)
To build op the filters you need to use a FiltersClass and all parameters you can set for the API are defined as properties. To use the facade to get the current weather, use the following:, (*10)
$filters = new \Rjvandoesburg\Apixu\Filters([ 'q' => 'London', ]); $response = \Apixu::current($filters);
This will return a CurrentResponse
which contains all properties returned.
You can use this response to easily output the response., (*11)
The available methods are:, (*12)
\Apixu::current($filters); \Apixu::forecast($filters); \Apixu::history($filters); \Apixu::search($filters);
or use the dependency injection method, (*13)
public function getWeather(\Rjvandoesburg\Apixu\ApixuClient $apixu) { $filters = new \Rjvandoesburg\Apixu\Filters([ 'q' => 'London', ]); return $apixu->current($filters) }
The MIT License (MIT). Please see License File for more information., (*14)