Skip to content

JoeyMckenzie/openbrewerydb-php-client

Repository files navigation

Open Brewery DB PHP API

CI

(Un)official PHP bindings for the Open Brewery DB API. Open Brewery DB provides a public dataset for breweries around the world, as well as offering an API to retrieve data in various forms. This library provides a straight and easy-to-use PHP bindings for querying the API

To get started, first install the package with composer:

$ composer require joeymckenzie/openbrewerydb-php-api

Next, instantiate the client from you code. Note, you should aim to only instantiate the client once as it uses Guzzle under the hood:

use GuzzleHttp\Exception\ConnectException;
use OpenBrewery\OpenBrewery\Breweries\BreweryType;
use OpenBrewery\OpenBrewery\ClientConnector;

$client = new ClientConnector();

// Get a list of breweries, based on all types of different search criteria
$breweries = $client->breweries()->list(type: BreweryType::BREWPUB);
var_dump($breweries);

// Retrieve various metadata about breweries from the API
$metadata = $client->breweries()->meta();
var_dump($metadata);

// Get a random brewery with a specified page size
$randomBrewery = $client->breweries()->random(5);
var_dump($randomBrewery);

// Optionally, provide a default timeout for all requests
$anotherClient = new ClientConnector(1.0);

try {
    $breweries = $anotherClient->breweries()->autocomplete('dog');
} catch (ConnectException $e) {
    // Handle retries, logging, events, etc.
    echo 'Request timed out';
}

For the entire set of APIs offered by Open Brewery DB, check out the docs on their website.

About

🍺 An Open Brewery DB API client for PHP.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages