PHP library for Petstore. Code is generated using the OpenAPI spec.
PHP >=8.0
Install the package with Composer:
composer require petstore/sdk
If you're missing a package providing psr/http-client-implementation
:
composer require php-http/guzzle7-adapter
Add autoloading:
require_once 'vendor/autoload.php';
Instantiate the SDK:
use Petstore\Petstore;
$petstore = new Petstore('YOUR_API_KEY', 'YOUR_API_URL');
$client = $petstore->client;
Or create a custom client:
use Petstore\Client;
$httpClient = \Http\Discovery\Psr18ClientDiscovery::find();
$uri = \Http\Discovery\Psr17FactoryDiscovery::findUriFactory()->createUri('YOUR_API_URL');
$bearer = new \Http\Message\Authentication\Bearer('YOUR_API_KEY');
$plugins = [
new \Http\Client\Common\Plugin\AddHostPlugin($uri),
new \Http\Client\Common\Plugin\AuthenticationPlugin($bearer),
];
$httpClient = new \Http\Client\Common\PluginClient($httpClient, $plugins);
$client = Client::create($httpClient);
Add a pet:
use Petstore\Petstore;
use Petstore\Model\Pet;
$petstore = new Petstore('YOUR_API_KEY');
$pet = new Pet();
$pet->setName('Neo');
$pet->setPhotoUrls(['https://placecats.com/neo/300/200']);
$response = $petstore->client->addPet($pet);
Handle an API error:
use Petstore\Petstore;
$petstore = new Petstore('YOUR_API_KEY');
try {
$petstore->client->getPetById(0);
} catch (Throwable $exception) {
echo $exception->getMessage();
echo $exception->getCode();
}
Generate the code:
composer build
Delete the lib/
directory:
composer clean
Run the tests:
composer test
This package is automatically generated by Jane.