biblionet-laravel maintained by ethelserth
ethelserth/biblionet-laravel
Laravel integration for ethelserth/biblionet-php, the PHP client for the Biblionet Greek books API.
This package provides a service provider, config publishing, and a facade so the Biblionet client works as a native Laravel citizen.
Requirements
- PHP 8.1 or higher
- Laravel 10, 11, 12, or 13
- Biblionet API credentials (request access at biblionet.gr)
Installation
composer require ethelserth/biblionet-laravel
Laravel's package auto-discovery will register the service provider and facade automatically.
Publish the config file:
php artisan vendor:publish --tag=biblionet-config
Add your credentials to .env:
BIBLIONET_USERNAME=your-username
BIBLIONET_PASSWORD=your-password
Usage
Via dependency injection (recommended)
use Ethelserth\Biblionet\BiblionetClient;
class BookController extends Controller
{
public function __construct(
private readonly BiblionetClient $biblionet,
) {}
public function show(int $id): JsonResponse
{
$title = $this->biblionet->getTitle($id);
return response()->json($title);
}
}
Via facade
use Ethelserth\BiblionetLaravel\Facades\Biblionet;
$title = Biblionet::getTitle(72584);
$summaries = Biblionet::getMonthTitles(2024, 1);
$contributors = Biblionet::getContributors(72584);
Via the container
$client = app(BiblionetClient::class);
$title = $client->getTitle(72584);
Configuration
After publishing, config/biblionet.php exposes:
| Key | Env variable | Default | Description |
|---|---|---|---|
username |
BIBLIONET_USERNAME |
'' |
Your Biblionet username |
password |
BIBLIONET_PASSWORD |
'' |
Your Biblionet password |
timeout |
BIBLIONET_TIMEOUT |
30 |
HTTP timeout in seconds |
Credentials are validated lazily — the application boots normally even if they are not set. The exception fires only when something first tries to resolve the client from the container.
Swapping the HTTP client
By default the package uses Guzzle as its PSR-18 HTTP client. If you have already bound Psr\Http\Client\ClientInterface in your application's service container, the package will use that instead:
// In your own AppServiceProvider
$this->app->bind(ClientInterface::class, fn() => new YourPreferredClient());
$this->app->bind(RequestFactoryInterface::class, fn() => new YourFactory());
$this->app->bind(StreamFactoryInterface::class, fn() => new YourFactory());
Testing
When testing code that uses the Biblionet client, mock BiblionetClient directly rather than faking HTTP:
use Ethelserth\Biblionet\BiblionetClient;
use Ethelserth\Biblionet\DTOs\Title;
$this->mock(BiblionetClient::class)
->shouldReceive('getTitle')
->with(72584)
->andReturn(new Title(...));
License
MIT. See LICENSE.