ClientProtocol

Trait ClientProtocol 

Source
pub trait ClientProtocol:
    Send
    + Sync
    + Debug {
    // Required methods
    fn protocol_id(&self) -> &ShapeId;
    fn serialize_request(
        &self,
        input: &dyn SerializableStruct,
        input_schema: &Schema,
        endpoint: &str,
        cfg: &ConfigBag,
    ) -> Result<Request, SerdeError>;
    fn deserialize_response<'a>(
        &self,
        response: &'a Response,
        output_schema: &Schema,
        cfg: &ConfigBag,
    ) -> Result<Box<dyn ShapeDeserializer + 'a>, SerdeError>;

    // Provided method
    fn update_endpoint(
        &self,
        request: &mut Request,
        endpoint: &Endpoint,
        cfg: &ConfigBag,
    ) -> Result<(), SerdeError> { ... }
}
Expand description

An object-safe client protocol for serializing requests and deserializing responses.

Each Smithy protocol (e.g., aws.protocols#restJson1, smithy.protocols#rpcv2Cbor) is represented by an implementation of this trait. Protocols combine one or more codecs and serializers to produce protocol-specific request messages and parse response messages.

§Lifecycle

ClientProtocol instances are immutable and thread-safe. They are typically created once and shared across all requests for a client. Serializers and deserializers are created per-request internally.

Required Methods§

Source

fn protocol_id(&self) -> &ShapeId

Returns the Smithy shape ID of this protocol.

This enables runtime protocol selection and differentiation. For example, aws.protocols#restJson1 or smithy.protocols#rpcv2Cbor.

Source

fn serialize_request( &self, input: &dyn SerializableStruct, input_schema: &Schema, endpoint: &str, cfg: &ConfigBag, ) -> Result<Request, SerdeError>

Serializes an operation input into an HTTP request.

§Arguments
  • input - The operation input to serialize.
  • input_schema - Schema describing the operation’s input shape.
  • endpoint - The target endpoint URI as a string.
  • cfg - The config bag containing request-scoped configuration (e.g., service name, operation name for RPC protocols).
Source

fn deserialize_response<'a>( &self, response: &'a Response, output_schema: &Schema, cfg: &ConfigBag, ) -> Result<Box<dyn ShapeDeserializer + 'a>, SerdeError>

Deserializes an HTTP response, returning a boxed ShapeDeserializer for the response body.

The returned deserializer reads only body members. For outputs with HTTP-bound members (headers, status code), generated code reads those directly from the response before using this deserializer for body members.

§Arguments
  • response - The HTTP response to deserialize.
  • output_schema - Schema describing the operation’s output shape.
  • cfg - The config bag containing request-scoped configuration.

Provided Methods§

Source

fn update_endpoint( &self, request: &mut Request, endpoint: &Endpoint, cfg: &ConfigBag, ) -> Result<(), SerdeError>

Updates a previously serialized request with a new endpoint.

Required by SEP requirement 7: “ClientProtocol MUST be able to update a previously serialized request with a new endpoint.” The orchestrator calls this after endpoint resolution, which happens after serialize_request.

The default implementation applies the endpoint URL (with prefix if present), sets the request URI, and copies any endpoint headers onto the request. This replicates the existing apply_endpoint logic from the orchestrator. Custom implementations should rarely need to override this.

Implementors§

Source§

impl<C> ClientProtocol for HttpBindingProtocol<C>
where C: Codec + Send + Sync + Debug + 'static, for<'a> C::Deserializer<'a>: ShapeDeserializer,

Source§

impl<C> ClientProtocol for HttpRpcProtocol<C>
where C: Codec + Send + Sync + Debug + 'static, for<'a> C::Deserializer<'a>: ShapeDeserializer,