1. Go to this page and download the library: Download jardisadapter/http 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/ */
jardisadapter / http example snippets
use JardisAdapter\Http\HttpClient;
use JardisAdapter\Http\Config\ClientConfig;
use JardisAdapter\Http\Message\Psr17Factory;
$psr17 = new Psr17Factory();
$client = new HttpClient($psr17, $psr17, $psr17, $psr17, new ClientConfig(
baseUrl: 'https://api.example.com/v2',
));
$response = $client->get('/users');
$data = json_decode((string) $response->getBody(), true);
$psr17 = new Psr17Factory();
$client = new HttpClient($psr17, $psr17, $psr17, $psr17, new ClientConfig(
bearerToken: 'eyJhbGciOiJI...',
));
// Authorization: Bearer eyJhbGciOiJI... is set automatically
$psr17 = new Psr17Factory();
$client = new HttpClient($psr17, $psr17, $psr17, $psr17, new ClientConfig(
basicUser: 'api-user',
basicPassword: 'secret',
));
$psr17 = new Psr17Factory();
$client = new HttpClient($psr17, $psr17, $psr17, $psr17, new ClientConfig(
maxRetries: 3, // Up to 3 retries on 5xx
retryDelayMs: 200, // Exponential backoff: 200ms, 400ms, 800ms
));
use JardisAdapter\Http\Exception\NetworkException;
try {
$response = $client->get('/users');
} catch (NetworkException $e) {
// Network problem — retry was already active (if configured)
}
if ($response->getStatusCode() >= 400) {
// Handle HTTP errors yourself
}
use JardisAdapter\Http\Message\Psr17Factory;
$factory = new Psr17Factory();
$request = $factory->createRequest('OPTIONS', 'https://api.example.com');
$response = $client->sendRequest($request);
$psr17 = new Psr17Factory();
$client = new HttpClient(
requestFactory: $psr17,
streamFactory: $psr17,
responseFactory: $psr17,
uriFactory: $psr17,
config: new ClientConfig(),
transport: function (RequestInterface $request, ClientConfig $config) use ($psr17) {
return $psr17->createResponse(200)
->withBody($psr17->createStream('{"mocked": true}'));
},
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.