A PHP client library for interacting with the JSONPlaceholder API, with easy Symfony integration.
- Simple and clean API client for JSONPlaceholder
- Easy integration with Symfony applications
- Customizable HTTP client configuration
- Optional clock emoji header for fun
Install the library via composer:
composer require hands-on-ekino-php/your-client
- Register the bundle in your
config/bundles.php
:
return [
// ...other bundles
HandsOnEkinoPhp\YourClient\Bridge\Symfony\HandsOnEkinoPhpBundle::class => ['all' => true],
];
- Configure the client in your
config/packages/hands_on.yaml
:
hands_on_ekino_php:
client:
clock_header: true # Set to false to disable the clock emoji header
name: todos_client # The name of your HTTP client service
- Configure your HTTP client in
config/packages/framework.yaml
:
framework:
http_client:
scoped_clients:
todos_client:
base_uri: 'https://jsonplaceholder.typicode.com'
- Use the client in your actions or services:
<?php
namespace App\Action;
use HandsOnEkinoPhp\YourClient\Client\TodosClient;
use Symfony\Component\HttpFoundation\JsonResponse;
class MyAction
{
public function __invoke(TodosClient $todosClient): JsonResponse
{
// The client is automatically injected thanks to Symfony's autowiring
return $todosClient->getTodos();
}
}
vendor/bin/phpunit
Contributions are welcome! Please feel free to submit a Pull Request.
This library is open-sourced software licensed under the MIT license.