PHP code example of swisnl / json-api-client-laravel
1. Go to this page and download the library: Download swisnl/json-api-client-laravel 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/ */
php
use Swis\JsonApi\Client\DocumentClient;
class RecipeController extends Controller
{
public function index(DocumentClient $client)
{
$document = $client->get('https://cms.contentacms.io/api/recipes');
/** @var \Swis\JsonApi\Client\Collection&\Swis\JsonApi\Client\Item[] $recipes */
$recipes = $document->getData();
foreach ($recipes as $recipe) {
// Do stuff with the recipe
}
}
}
php
class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function register()
{
$this->app->bind(\Swis\JsonApi\Client\Client::class, function ($app) {
if ($app->environment('testing')) {
$httpClient = new \Swis\Http\Fixture\Client(
new \Swis\Http\Fixture\ResponseBuilder('/path/to/fixtures')
);
} else {
$httpClient = new \GuzzleHttp\Client(
[
'http_errors' => false,
'timeout' => 2,
]
);
}
return new \Swis\JsonApi\Client\Client($httpClient);
});
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.