Search by

smithy / protocol

stobrien89smithy

Converts Smithy operations and shapes to HTTP requests and responses.

0.1.0-RC.5 2026-11-27 19:05 UTC

This package is auto-updated.

Last update: 2026-11-27 19:55:32 UTC


README

Converts Smithy operations and shapes to HTTP requests and responses. Requires PHP 8.2 or later.

Installation

composer require smithy/protocol

Protocol Contract

ProtocolInterface defines the request and response boundary:

$request = $protocol->serializeRequest(
    $operation,
    $input,
);

$request = $protocol->setServiceEndpoint(
    $request,
    $endpoint,
);

$output = $protocol->deserializeResponse(
    $operation,
    $response,
);

Clients serialize an operation-relative request once before the retry loop. Each request attempt resolves and binds its service endpoint before signing. Protocols declare their request/response message exchange so configuration can reject an incompatible transport before execution. HTTP protocols use HttpTransportRequest and HttpTransportResponse, whose payloads remain PSR-7 messages at the HTTP boundary.

Operations supply input, output, error, and HTTP metadata through runtime schemas. Protocol implementations use codecs for body encoding.

HTTP Bindings

AbstractHttpBindingProtocol handles Smithy HTTP binding traits. It composes:

  • HttpBindingSerializer for URI labels, queries, headers, payloads, and document bodies
  • HttpBindingDeserializer for response headers, status codes, payloads, and document bodies
  • HttpErrorDeserializer for modeled and unmodeled service errors

Schema extension providers precompute operation and structure binding data. Each request reads the precomputed binding routes.

RPC v2 CBOR

RpcV2CborProtocol implements the public smithy.protocols#rpcv2Cbor protocol using the CBOR codec.

use Smithy\Protocol\RpcV2\RpcV2CborProtocol;

$protocol = new RpcV2CborProtocol();

RPC v2 JSON

RpcV2JsonProtocol implements the public smithy.protocols#rpcv2Json protocol using the JSON codec.

use Smithy\Protocol\RpcV2\RpcV2JsonProtocol;

$protocol = new RpcV2JsonProtocol();

Component Boundaries

Codecs own body formats such as JSON, XML, and CBOR. The HTTP package owns messages and transfer behavior. This package owns operation framing, HTTP member routing, and response interpretation.

Dependencies

This package depends on smithy/codec, smithy/core, smithy/http, and psr/http-message.

The AWS protocols (Smithy\Protocol\Aws) live in smithy/protocol-aws.

Design

See Protocol Design.

Contributing

Run the component tests from the monorepo root:

vendor/bin/phpunit tests/Protocol