aws_smithy_json/protocol/
aws_rest_json_1.rs

1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6//! AWS REST JSON 1.0 protocol implementation.
7//!
8//! This module provides [`AwsRestJsonProtocol`], which constructs an
9//! [`HttpBindingProtocol`] with a [`JsonCodec`] configured for the
10//! `aws.protocols#restJson1` protocol:
11//!
12//! - Uses `@jsonName` trait for JSON property names
13//! - Default timestamp format: `epoch-seconds`
14//! - Content-Type: `application/json`
15
16use crate::codec::{JsonCodec, JsonCodecSettings};
17use aws_smithy_schema::http_protocol::HttpBindingProtocol;
18use aws_smithy_schema::{Schema, ShapeId};
19use aws_smithy_types::config_bag::ConfigBag;
20
21static PROTOCOL_ID: ShapeId = ShapeId::from_static("aws.protocols", "restJson1", "");
22
23/// AWS REST JSON 1.0 protocol (`aws.protocols#restJson1`).
24///
25/// This is a thin configuration wrapper that constructs an [`HttpBindingProtocol`]
26/// with a [`JsonCodec`] using REST JSON settings. The `HttpBindingProtocol` handles
27/// splitting members between HTTP bindings and the JSON payload.
28#[derive(Debug)]
29pub struct AwsRestJsonProtocol {
30    inner: HttpBindingProtocol<JsonCodec>,
31}
32
33impl AwsRestJsonProtocol {
34    /// Creates a new REST JSON protocol with default settings.
35    pub fn new() -> Self {
36        let codec = JsonCodec::new(
37            JsonCodecSettings::builder()
38                .use_json_name(true)
39                .default_timestamp_format(aws_smithy_types::date_time::Format::EpochSeconds)
40                .build(),
41        );
42        Self {
43            inner: HttpBindingProtocol::new(PROTOCOL_ID, codec, "application/json"),
44        }
45    }
46
47    /// Returns a reference to the inner `HttpBindingProtocol`.
48    pub fn inner(&self) -> &HttpBindingProtocol<JsonCodec> {
49        &self.inner
50    }
51}
52
53impl Default for AwsRestJsonProtocol {
54    fn default() -> Self {
55        Self::new()
56    }
57}
58
59impl aws_smithy_schema::protocol::ClientProtocol for AwsRestJsonProtocol {
60    fn protocol_id(&self) -> &ShapeId {
61        self.inner.protocol_id()
62    }
63
64    fn serialize_request(
65        &self,
66        input: &dyn aws_smithy_schema::serde::SerializableStruct,
67        input_schema: &Schema,
68        endpoint: &str,
69        cfg: &ConfigBag,
70    ) -> Result<aws_smithy_runtime_api::http::Request, aws_smithy_schema::serde::SerdeError> {
71        self.inner
72            .serialize_request(input, input_schema, endpoint, cfg)
73    }
74
75    fn deserialize_response<'a>(
76        &self,
77        response: &'a aws_smithy_runtime_api::http::Response,
78        output_schema: &Schema,
79        cfg: &ConfigBag,
80    ) -> Result<
81        Box<dyn aws_smithy_schema::serde::ShapeDeserializer + 'a>,
82        aws_smithy_schema::serde::SerdeError,
83    > {
84        self.inner
85            .deserialize_response(response, output_schema, cfg)
86    }
87}