It's not clear how you use the data from the API, but you may find Laravel's caching capabilities quite handy. Specifically remember()
method.
use Illuminate\Support\Facades\Cache;
// Put the result returned from the closure in the cache for 30 days
// under the key 'apidata' and serve this data off of cache if it already there
$apidata = Cache::remember('apidata', 60*24*30, function() {
// talk to your API
// and return the data from this closure
return $result;
});
You can make a step further and wrap it in a service class to make your life easier. Something along the lines of
namespace App;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Cache;
class ApiData
{
protected $client;
public function __construct(Client $client)
{
$this->client = $client;
}
public function all()
{
return Cache::remember('apidata', 60*24*30, function() {
$response = $this->client->get('http://httpbin.org/get');
return $response->getBody()->getContents();
});
}
}
Then use it
// Get an instance off of IoC container
$api = app('App\ApiData');
$apidata = $api->all();