- Création API recherche

This commit is contained in:
2025-01-29 10:15:16 +01:00
parent 3797ef0582
commit f2dd1047a1
6 changed files with 249 additions and 1 deletions

View File

@ -0,0 +1,31 @@
<?php
namespace App\Service;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class GoogleBooksService
{
private HttpClientInterface $client;
public function __construct(HttpClientInterface $client)
{
$this->client = $client;
}
public function searchBooks(string $query, string $lang = 'fr'): array
{
$url = 'https://www.googleapis.com/books/v1/volumes';
$response = $this->client->request('GET', $url, [
'query' => [
'q' => $query,
'langRestrict' => $lang,
],
]);
// Convertir la réponse JSON en tableau PHP
$dataArray = $response->toArray();
dump($dataArray);
return $dataArray;
}
}