This library provides a PHP client to interact with jsonplaceholder shipped with a Symfony bundle to easy integrate it in a Symfony project.
$ composer require hands-on-ekino-php/your-client
<?php
// config/bundles.php
return [
// ...
HandsOnEkinoPhp\YourClient\Bridge\Symfony\HandsOnEkinoPhpBundle::class => ['all' => true],
// ...
];
# config/packages/framework.yaml
framework:
# ...
http_client:
scoped_clients:
todos_client:
base_uri: 'https://jsonplaceholder.typicode.com'
headers:
Content-type: 'application/json'
# ...
# config/packages/ekino_vw_http_clients.yaml
hands_on_ekino_php:
client:
name: 'todos_client' # use the same name your configured as client in framework.yaml
clock_header: true # default false
Inject your client, and enjoy !
<?php
use HandsOnEkinoPhp\YourClient\Client\TodosClient;
class MyService
{
private $clientApi;
public function __construct(private TodosClient $todosClient) {
}
public function doSmth()
{
$this->todosClient->getTodos();
}
}