wrkflow / php-api-sdk-builder
This package helps you build PHP clients for external APIs with dependency injection and type strict code in mind.
Fund package maintenance!
Requires
- php: >=8.1
- guzzlehttp/psr7: ^2.5
- php-http/discovery: ^1.14
- psr/http-client: ^1.0.1
- psr/http-message: ^1.0.1 || ^2.0
- wrkflow/php-get-typed-value: ^0.8.2 || ^0.9.0
Requires (Dev)
- ext-simplexml: *
- guzzlehttp/guzzle: ^7.4
- http-interop/http-factory-guzzle: ^1.2
- laravel/framework: ^10.0
- laravel/telescope: ^4.14.2
- league/flysystem: ^3.14
- mockery/mockery: ^1.5.1
- nyholm/psr7: ^1.8.0
- orchestra/testbench: ^8.0
- php-http/mock-client: ^1.6
- phpstan/phpstan-mockery: ^2.0
- phpunit/phpunit: ^10.5
- strictphp/conventions: ^2.1
Suggests
- laravel/framework: SDKs work great with Laravel - solid container.
- wrkflow/larastrict: Improve your Laravel code base with strict conventions.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-05 17:27:43 UTC
README
Build unified APIs with dependency injection and strict code in mind.
composer require wrkflow/php-api-sdk-builder
This package is still in its early stages. But the main concepts will probably remain same.
This package helps you build PHP clients for external APIs with dependency injection and type strict code in mind.
Why to use?
- If you want to consume external API without losing type strict code (Data transfer objects instead of array keys).
- If you work with multiple APIs and want to use the same conventions.
- If you want to provide type strict way to build request parameters.
- If you want to save time building HTTP/s request.
Features
- 🛠 Dependency injection using your favorite framework (Laravel, PR for more)
- ✅ Uses PSR packages you already use for HTTP/S communication
- 🏆 Forcing type strict implementation for input (request options) and output (
Response) - 🎗 Encouraging
Data transfer objects - 🎭 Re-usable and configurable headers using objects
Optional LaraStrict integration
Class-placement rules belong to larastrict/conventions. This optional adapter
extends those rules for SDK classes. Shared development tools and AI registration
use strictphp/conventions.
With phpstan/extension-installer, the SDK placement extension loads
automatically when the LaraStrict ClassPlacementExtension interface is available.
Without that interface, the configuration returns no services. Runtime SDK use
does not require LaraStrict.
Without the extension installer, add this file after LaraStrict in your
application's phpstan.neon:
includes: - vendor/larastrict/conventions/extension.neon - vendor/wrkflow/php-api-sdk-builder/phpstan/extension.php
Entities may then stay beside their endpoint in Endpoints/{endpoint}, including
App/Orders/Sdk/Endpoints/Devices/DeviceEntity.php. Shared Entities keep their
Entities folder. The extension also supports SDK roots named Api or another
name. It requires an endpoint folder and preserves the other placement rules.
The adapter checks SDK constructor arguments by type and requires their factory
names: endpoint $di, and response $response, $body, or $container when
those arguments are accepted. GetValue in a response constructor is named
$body; unrelated inputs and methods keep their names. Constructors may accept
additional injected collaborators. Those
collaborators receive naming and container-lookup checks. Endpoints and Responses
are constructed through the SDK factory, so the adapter does not add them to the
plain container-resolvability rule.
For extension development, install a compatible larastrict/conventions version
as a development dependency, then run composer test:larastrict. These tests
check the SDK allowance against the actual LaraStrict placement rule.
AI conventions
The package registers the general api-sdk-builder skill through
extra.strictphp/conventions.skills. To install the AI instructions in your
application, use PHP 8.3 or later and install StrictPHP as a development dependency:
composer require --dev strictphp/conventions:^2.1 vendor/bin/strictphp-sync-ai
Installing the SDK alone does not install StrictPHP. The sync command installs
the SDK skill with the shared PHP skill and collects package rules in AGENTS.md.
This works with or without LaraStrict. Read the skill for SDK conventions;
LaraStrict-specific integration applies only when LaraStrict is installed.
Run the sync command again after dependency updates, or configure Composer hooks
as described in the StrictPHP setup guide.
Use vendor/bin/strictphp-sync-ai --check to check that the instructions are current.
Development
Development uses strictphp/conventions:^2.1 for Rector, ECS, and PHPStan.
Install development dependencies with PHP 8.3 or later. Runtime consumers can
continue to use PHP 8.1 or later without the development tools.
Run composer qa to apply Rector, then ECS, then run PHPStan and tests.
Use composer lint:upgrade:check, composer lint:check, composer analyse,
and composer test for validation without code transformations.
Laravel dependencies support the adapter tests; the SDK does not require
larastrict/conventions for its normal development workflow.
For development read CONTRIBUTIONS