smithy / client
Schema-driven client runtime for generated and runtime-loaded Smithy services.
Requires
- php: >=8.2
- ext-ctype: *
- ext-filter: *
- mtdowling/jmespath.php: ^2.9.1
- psr/http-message: ^2.0
- smithy/async: 0.1.0-RC.5
- smithy/auth: 0.1.0-RC.5
- smithy/core: 0.1.0-RC.5
- smithy/http: 0.1.0-RC.5
- smithy/protocol: 0.1.0-RC.5
Requires (Dev)
None
Suggests
- ext-zlib: Enables gzip request compression.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-27 19:55:32 UTC
README
Schema-driven client runtime for generated and runtime-loaded Smithy services. Requires PHP 8.2 or later.
Installation
composer require smithy/client
Client Execution
Generated service clients extend AbstractClient. Each generated operation
method delegates to executeOperation() with operation metadata and a typed
input shape.
use Smithy\Client\AbstractClient; final class WeatherClient extends AbstractClient { public function getForecast( GetForecastInput $input ): GetForecastOutput { return $this->executeOperation( GetForecastOperation::instance(), $input, ); } }
ClientPipeline resolves an endpoint, serializes the request, selects an
authentication scheme, transmits through the configured HTTP client, applies
retry decisions, and deserializes the response. Interceptors run at the
documented pipeline stages.
Configuration
ClientConfig holds the runtime dependencies for one client:
- protocol implementation
- HTTP client
- endpoint resolver
- protocol resolver and optional explicit protocol selection
- authentication schemes and identity resolvers
- retry strategy
- interceptors and plugin state
Configuration objects are immutable. The withXxx() methods return a copy
with one dependency replaced.
Runtime Features
| Namespace | Responsibility |
|---|---|
Smithy\Client\Auth |
Authentication scheme selection; schemes, identities, and signers are in smithy/auth |
Smithy\Client\Endpoint |
Static and bytecode endpoint resolvers; the resolved Endpoint value lives in Smithy\Core\Endpoint |
Smithy\Client\Interceptor |
Request pipeline hooks and contexts |
Smithy\Client\Pagination |
Schema-driven paginators |
Smithy\Client\Plugin |
Reusable client configuration changes |
Smithy\Client\Retry |
Retry strategies and request flags |
Smithy\Client\Waiter |
Modeled polling and acceptor evaluation |
Dynamic Clients
DynamicClient loads a Smithy JSON AST at runtime and invokes operations by
name using document-backed inputs and outputs. This example uses a model with
the built-in smithy.protocols#rpcv2Cbor protocol.
use Smithy\Client\Dynamic\DynamicClient; $client = DynamicClient::create( model: __DIR__ . '/weather.json', endpoint: 'http://localhost:8080', ); $output = $client->call('GetForecast', [ 'city' => 'Raleigh', ]);
Modeled paginated operations return a lazy paginator that yields one
StructDocument per response page:
$pages = $client->paginate('ListForecasts', [ 'city' => 'Raleigh', 'pageSize' => 25, ]); // Equivalent to the generated-client naming convention. $pages = $client->listForecastsPaginated([ 'city' => 'Raleigh', 'pageSize' => 25, ]); foreach ($pages as $page) { $forecasts = $page->getMember('forecasts')?->asList() ?? []; }
Pagination stops when a response returns the same token that was sent with
its request. Some services repeat tokens by design, such as tailing log
streams. Call withStopOnSameToken(false) to keep paginating until the token
is empty or the max items limit is reached:
$pages = $client->paginate('ListForecasts', ['city' => 'Raleigh']) ->withStopOnSameToken(false);
Modeled waiters are available by their Smithy waiter name. The result retains the output or modeled error that satisfied the success acceptor:
$result = $client->waitUntil( waiterName: 'ForecastReady', input: ['city' => 'Raleigh'], maxWaitTime: 60.0, ); $result = $client->waitUntilForecastReady( ['city' => 'Raleigh'], 60.0, ); $forecast = $result->output;
Generated and dynamic clients use the same protocol resolver. It selects the
first registered implementation modeled as a trait on the service schema,
unless the caller explicitly chooses a protocol implementation or shape ID.
Provider subclasses add protocols, authentication schemes, endpoint
functions, and schema traits through an internal DynamicClientRuntime.
Dependencies
This package builds on smithy/async, smithy/auth, smithy/core,
smithy/http, smithy/protocol, and psr/http-message. Waiter path expressions use
mtdowling/jmespath.php.
Design
Contributing
Run the component tests from the monorepo root:
vendor/bin/phpunit tests/Client