jooservices/client

A robust, layered HTTP Client wrapper for JOOservices

Maintainers

Package info

github.com/jooservices/client

pkg:composer/jooservices/client

Statistics

Installs: 19

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.1.0 2026-03-09 23:15 UTC

This package is auto-updated.

Last update: 2026-03-09 23:19:31 UTC


README

A robust, layered HTTP Client wrapper designed for extensibility, strict typing, and high performance. Built with a "Clean Architecture" approach, decoupling the business logic from the underlying Guzzle transport.

PHP Version License

Features

  • Strictly Typed: Configuration object (ClientConfig) ensures type safety before requests start.
  • Layered Architecture: Adapters (Guzzle) are isolated from Core Logic.
  • Resilience: Built-in Retry (Backoff/Jitter) and Circuit Breaker.
  • Async & Concurrency: Support for non-blocking requests (getAsync) and Batch Processing.
  • Observability: detailed Logging and PSR-16 Caching integration.
  • Performance: < 10μs overhead per request.

Installation

composer require jooservices/client

Quick Start

Basic Usage

Use the ClientBuilder to create an instance.

use JOOservices\Client\Client\ClientBuilder;

$client = ClientBuilder::create()
    ->withBaseUri('https://api.example.com')
    ->withTimeout(5)
    ->withHeader('Authorization', 'Bearer token')
    ->build();

$response = $client->get('/users/1');

echo $response->status(); // 200
print_r($response->json()); // ['id' => 1, ...]

Async Requests & Batching

// Single Async Request
$promise = $client->getAsync('/users/1');
$response = $promise->wait();

// Batch Processing (Concurrent)
$results = $client->batch([
    'user1' => fn() => $client->getAsync('/users/1'),
    'user2' => fn() => $client->getAsync('/users/2'),
]);

print_r($results['user1']->json());

Advanced Configuration

Resilience (Retry & Circuit Breaker)

use JOOservices\Client\Resilience\RetryConfig;
use JOOservices\Client\Resilience\CircuitBreakerConfig;

$client = ClientBuilder::create()
    ->withRetry(new RetryConfig(
        maxAttempts: 3,
        baseDelayMs: 100
    ))
    ->withCircuitBreaker(new CircuitBreakerConfig(
        failureThreshold: 5,
        recoveryTimeoutMs: 10000
    ))
    ->build();

Logging & Caching

use JOOservices\Client\Logging\MonologFactory;
use JOOservices\Client\Cache\FilesystemCache;

$logger = MonologFactory::createDaily('my-app', __DIR__ . '/logs');
$cache = new FilesystemCache(__DIR__ . '/cache');

$client = ClientBuilder::create()
    ->withLogger($logger, logBodies: true)
    ->withCache($cache, defaultTtl: 3600)
    ->build();

Quality Assurance

We use strict static analysis and testing.

composer quality

This runs:

  • Pint: Code Style Fixer
  • PHPStan: Static Analysis (Level 9)
  • PHPUnit: Unit, Feature & Integration Tests (with 98% coverage gate)
  • PHPBench: Performance Analysis

Docker Development

If PHP is not installed locally, run everything in Docker.

docker compose up -d --build mongodb
docker compose run --rm php composer install
docker compose run --rm php composer test

For live network integration tests (real sites), run:

docker compose run --rm -e JOOCLIENT_RUN_LIVE_NETWORK_TESTS=1 php \
    vendor/bin/phpunit tests/Feature/Logging/RealSiteIpLoggingTest.php

This test hits:

  • https://httpbin.org/get
  • https://example.com
  • https://google.com

Contributing

See CONTRIBUTING.md for details.