1. Go to this page and download the library: Download codecoz/laravel-rest-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Cache response for 10 minutes
RestClient::cache(600)->get('/slow-endpoint');
// Disable caching for a specific call
RestClient::withoutCache()->get('/real-time-data');
// app/Services/GitHubApiClient.php
namespace App\Services;
use CodeCoz\Laravel\RestClient\Facades\RestClient;
class GitHubApiClient
{
public function __construct()
{
RestClient::withToken(config('services.github.token'))
->baseUrl('https://api.github.com');
}
public function getUser(string $username)
{
return RestClient::cache(300)
->get("/users/{$username}")
->json();
}
public function getRepos(string $username)
{
return RestClient::get("/users/{$username}/repos")->json();
}
public function createIssue(string $owner, string $repo, array $data)
{
return RestClient::post("/repos/{$owner}/{$repo}/issues", $data)->json();
}
}
$github = new App\Services\GitHubApiClient();
$user = $github->getUser('torvalds');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.