PHPackages                             daniel-jorg-schuppelius/php-api-toolkit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. daniel-jorg-schuppelius/php-api-toolkit

ActiveLibrary

daniel-jorg-schuppelius/php-api-toolkit
=======================================

Reused codes for my api php sdks

v2.2.4.2(3d ago)089↓100%1MITPHPPHP &gt;=8.1 &lt;8.6CI passing

Since Oct 22Pushed 3d ago1 watchersCompare

[ Source](https://github.com/Daniel-Jorg-Schuppelius/php-api-toolkit)[ Packagist](https://packagist.org/packages/daniel-jorg-schuppelius/php-api-toolkit)[ RSS](/packages/daniel-jorg-schuppelius-php-api-toolkit/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (4)Versions (41)Used By (1)

PHP API Toolkit
===============

[](#php-api-toolkit)

A reusable PHP library for building API client SDKs, targeting PHP 8.2+ with modern patterns and PSR compliance.

Features
--------

[](#features)

- **HTTP Client Abstraction** - Built on GuzzleHttp with automatic rate limiting and retry logic
- **Authentication Strategies** - Built-in support for Bearer, Basic, and API Key authentication
- **Exception Mapping** - HTTP status codes automatically mapped to specific exceptions
- **Entity System** - Type-safe data objects with automatic hydration and validation
- **PSR-3 Logging** - Comprehensive logging integration
- **Timeouts** - Configurable request and connection timeouts
- **Proxy Support** - Enterprise-ready proxy configuration
- **Default Headers &amp; Query Params** - Global request configuration
- **SSL Control** - Optional SSL verification bypass for development

Installation
------------

[](#installation)

```
composer require dschuppelius/php-api-toolkit
```

Quick Start
-----------

[](#quick-start)

```
use APIToolkit\Contracts\Abstracts\API\Authentication\BearerAuthentication;

// Create your API client extending ClientAbstract
// Simply pass the base URL - HttpClient is created internally
$apiClient = new MyApiClient('https://api.example.com', $logger);

// Set authentication
$auth = new BearerAuthentication('your-token');
$apiClient->setAuthentication($auth);

// Make requests - auth headers are added automatically
$response = $apiClient->get('/endpoint');
```

### Advanced: Custom HttpClient

[](#advanced-custom-httpclient)

For advanced use cases (custom middleware, handler stacks, etc.), you can still provide your own HttpClient:

```
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\HandlerStack;

$stack = HandlerStack::create();
// Add custom middleware...

$httpClient = new HttpClient([
    'base_uri' => 'https://api.example.com',
    'handler' => $stack,
]);

$apiClient = new MyApiClient('https://api.example.com', $logger, false, $httpClient);
```

Authentication
--------------

[](#authentication)

The toolkit provides three authentication strategies out of the box:

### Bearer Token (OAuth2, JWT)

[](#bearer-token-oauth2-jwt)

```
use APIToolkit\Contracts\Abstracts\API\Authentication\BearerAuthentication;

$auth = new BearerAuthentication('your-jwt-token');
$client->setAuthentication($auth);

// Update token later (e.g., after refresh)
$auth->setToken('new-refreshed-token');
```

### Basic Authentication

[](#basic-authentication)

```
use APIToolkit\Contracts\Abstracts\API\Authentication\BasicAuthentication;

$auth = new BasicAuthentication('username', 'password');
$client->setAuthentication($auth);
```

### API Key

[](#api-key)

```
use APIToolkit\Contracts\Abstracts\API\Authentication\ApiKeyAuthentication;

// Default header: X-API-Key
$auth = new ApiKeyAuthentication('your-api-key');

// Custom header name
$auth = new ApiKeyAuthentication('your-api-key', 'X-Custom-Auth');
$client->setAuthentication($auth);
```

### Custom Authentication

[](#custom-authentication)

Implement `AuthenticationInterface` for custom auth strategies:

```
use APIToolkit\Contracts\Interfaces\API\AuthenticationInterface;

class OAuth1Authentication implements AuthenticationInterface {
    public function getAuthHeaders(): array {
        return ['Authorization' => 'OAuth ' . $this->buildOAuthHeader()];
    }

    public function getType(): string {
        return 'OAuth1';
    }

    public function isValid(): bool {
        return !empty($this->consumerKey);
    }
}
```

Rate Limiting
-------------

[](#rate-limiting)

```
// Set minimum interval between requests (default: 0.25s, minimum: 0.2s)
$client->setRequestInterval(0.5); // 500ms between requests
```

Retry Logic
-----------

[](#retry-logic)

```
// Configure retry behavior for 429, 503, 504 errors
$client->setMaxRetries(5);
$client->setBaseRetryDelay(2); // seconds
$client->setExponentialBackoff(true); // delays: 2s, 4s, 8s, 16s...
```

Timeouts
--------

[](#timeouts)

```
// Request timeout (default: 30s)
$client->setTimeout(60.0);

// Connection timeout (default: 10s)
$client->setConnectTimeout(5.0);
```

Default Headers
---------------

[](#default-headers)

```
// Set headers included in every request
$client->setDefaultHeaders([
    'Content-Type' => 'application/json;charset=utf-8',
    'Accept' => 'application/json;charset=utf-8',
]);

// Add/remove individual headers
$client->addDefaultHeader('X-Custom-Header', 'value');
$client->removeDefaultHeader('X-Custom-Header');
```

Default Query Parameters
------------------------

[](#default-query-parameters)

```
// Set query parameters included in every request
$client->setDefaultQueryParams([
    'api_version' => '2.0',
    'format' => 'json',
]);

// Add/remove individual parameters
$client->addDefaultQueryParam('locale', 'de_DE');
$client->removeDefaultQueryParam('format');
```

User-Agent
----------

[](#user-agent)

```
$client->setUserAgent('MyApp/1.0.0 (PHP 8.2)');
```

Proxy Support
-------------

[](#proxy-support)

```
// Set proxy for enterprise environments
$client->setProxy('http://proxy.company.com:8080');

// With authentication
$client->setProxy('http://user:pass@proxy.company.com:8080');

// Disable proxy
$client->setProxy(null);
```

SSL Verification
----------------

[](#ssl-verification)

```
// Disable SSL verification (development only!)
$client->setVerifySSL(false);

// Check status
$client->isSSLVerificationEnabled();
```

> ⚠️ **Warning:** Disabling SSL verification is insecure. Only use for development or self-signed certificates.

Complete Configuration Example
------------------------------

[](#complete-configuration-example)

```
use APIToolkit\Contracts\Abstracts\API\Authentication\BearerAuthentication;

// Simple constructor - just base URL
$client = new MyApiClient('https://api.example.com', $logger);

// Timeouts
$client->setTimeout(30.0);
$client->setConnectTimeout(10.0);

// Default headers
$client->setDefaultHeaders([
    'Content-Type' => 'application/json;charset=utf-8',
    'Accept' => 'application/json;charset=utf-8',
]);

// User-Agent
$client->setUserAgent('MyApp/1.0.0');

// Default query parameters
$client->setDefaultQueryParams(['api_version' => '2']);

// Authentication with additional headers
$auth = new BearerAuthentication($token, [
    'X-Client-ID' => $clientId,
]);
$client->setAuthentication($auth);

// Rate limiting
$client->setRequestInterval(0.5);
$client->setMaxRetries(3);

// Enterprise environment (optional)
$client->setProxy('http://proxy:8080');
$client->setVerifySSL(false); // Development only!
```

Exception Handling
------------------

[](#exception-handling)

HTTP errors are automatically converted to typed exceptions:

```
use APIToolkit\Exceptions\TooManyRequestsException;
use APIToolkit\Exceptions\UnauthorizedException;
use APIToolkit\Exceptions\NotFoundException;

try {
    $response = $client->get('/resource');
} catch (UnauthorizedException $e) {
    // 401 - Invalid or expired token
} catch (NotFoundException $e) {
    // 404 - Resource not found
} catch (TooManyRequestsException $e) {
    // 429 - Rate limited
}
```

Status CodeException400`BadRequestException`401`UnauthorizedException`402`PaymentRequiredException`403`ForbiddenException`404`NotFoundException`405`NotAllowedException`406`NotAcceptableException`408`RequestTimeoutException`409`ConflictException`415`UnsupportedMediaTypeException`422`UnprocessableEntityException`429`TooManyRequestsException`500`InternalServerErrorException`502`BadGatewayException`503`ServiceUnavailableException`504`GatewayTimeoutException`Testing
-------

[](#testing)

```
composer test
# or
vendor/bin/phpunit
```

License
-------

[](#license)

MIT License - see [LICENSE](LICENSE) for details.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance99

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 88.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~13 days

Total

40

Last Release

3d ago

Major Versions

v1.5.6 → v2.02025-12-29

PHP version history (5 changes)v1.2.0PHP ^8.2 || ^8.3

v2.0.2PHP &gt;=8.2 &lt;8.5

v2.0.3PHP &gt;=8.1 &lt;8.5

v2.2.4.1PHP &gt;=8.1 &lt;=8.5

v2.2.4.2PHP &gt;=8.1 &lt;8.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d648df75b8ca254b14377de6aa7c37daff5bc21e9e8742ef7687c7091c7bc94?d=identicon)[l0gtr0n](/maintainers/l0gtr0n)

---

Top Contributors

[![DSchuppelius](https://avatars.githubusercontent.com/u/19145058?v=4)](https://github.com/DSchuppelius "DSchuppelius (74 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (10 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/daniel-jorg-schuppelius-php-api-toolkit/health.svg)

```
[![Health](https://phpackages.com/badges/daniel-jorg-schuppelius-php-api-toolkit/health.svg)](https://phpackages.com/packages/daniel-jorg-schuppelius-php-api-toolkit)
```

###  Alternatives

[mvdnbrk/dhlparcel-php-api

DHL Parcel API client for PHP

3957.6k4](/packages/mvdnbrk-dhlparcel-php-api)[walle89/swedbank-json

Unofficial API client for the Swedbank's and Sparbanken's mobile apps in Sweden.

752.5k](/packages/walle89-swedbank-json)[soukicz/llm

LLM client with support for cache, tools and async requests

434.1k](/packages/soukicz-llm)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
