1. Go to this page and download the library: Download tcds-io/php-jackson-guzzle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tcds-io / php-jackson-guzzle example snippets
use GuzzleHttp\Client;
use Tcds\Io\Jackson\Guzzle\JacksonClient;
$client = new JacksonClient(
new Client([
'base_uri' => 'https://api.example.com',
]),
);
readonly class Address
{
public function __construct(
public string $id,
public string $street,
public int $number,
public bool $main,
) {}
}
$address = $client->get(Address::class, '/addresses/aaa');
readonly class CreateAddress
{
public function __construct(
public string $street,
public int $number,
) {}
}
readonly class AddressCreated
{
public function __construct(public string $id) {}
}
$created = $client->post(
class: AddressCreated::class,
uri: '/addresses',
jsonBody: new CreateAddress(street: 'Ocean Avenue', number: 42),
);