Api Connector
A Laravel package to consume and cache API calls., (*1)
WAAVI is a web development studio based in Madrid, Spain. You can learn more about us at waavi.com, (*2)
Installing
Require through Composer, (*3)
composer require waavi/api-connector dev-master
Or manually edit your composer.json file, (*4)
"require": {
"waavi/api-connector": "dev-master"
}
Configuration
Once installed, edit your config/app.php add the following entry to the providers array:, (*5)
Waavi\ApiConnector\ApiConnectorServiceProvider::class
Usage
Once installed and configured you will be able to make API calls using the ApiConnector interface like so:, (*6)
<?php
namespace App\Http\Controllers;
use Waavi\ApiConnector\ApiConnector;
class HomeControllerController extends Controller
{
protected $connector;
public function __construct(ApiConnector $connector)
{
$this->connector = $connector;
}
public function index()
{
// A GET call to https://someapi.com/v1/resource
$resourcesList = $this->connector->get('resource');
// A GET call to https://someapi.com/v1/resource?size=20&page=3
$otherResourcesList = $this->connector->get('resource', ['size=20', 'page=3']);
// A GET call to https://someapi.com/v1/resource/{id}
$resource = $this->connector->get('resource/1');
return view('web.home')->with(compact('resourcesList', 'otherResourcesList', 'resource'));
}
}
By default, the calls will be cached and retrieved from the cache on subsequent calls. If you wish to disable this behaviour just edit your config., (*7)
Built With
License
This project is licensed under the MIT License - see the LICENSE.md file for details, (*8)
xkcd because yes
, (*9)