Skip to content

Commit

Permalink
Update design docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-sdk-rust-ci committed Oct 30, 2023
1 parent 9c8e19b commit 9056936
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 84 deletions.
131 changes: 90 additions & 41 deletions design/print.html

Large diffs are not rendered by default.

35 changes: 30 additions & 5 deletions design/rfcs/rfc0037_http_wrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ <h4 id="proposed-implementation"><a class="header" href="#proposed-implementatio

//! Http Request Types

use aws_smithy_http::body::SdkBody;
use aws_smithy_types::body::SdkBody;
use http as http0;
use http::header::{InvalidHeaderName, InvalidHeaderValue};
use http::uri::InvalidUri;
Expand Down Expand Up @@ -629,7 +629,7 @@ <h4 id="proposed-implementation"><a class="header" href="#proposed-implementatio
key: impl AsHeaderComponent,
value: impl AsHeaderComponent,
) -&gt; Result&lt;Option&lt;String&gt;, HttpError&gt; {
let key = header_name(key.into_maybe_static()?)?;
let key = header_name(key)?;
let value = header_value(value.into_maybe_static()?)?;
Ok(self
.headers
Expand All @@ -653,8 +653,10 @@ <h4 id="proposed-implementation"><a class="header" href="#proposed-implementatio
/// Removes all headers with a given key
///
/// If there are multiple entries for this key, the first entry is returned
pub fn remove(&amp;mut self, key: &amp;str) -&gt; Option&lt;HeaderValue&gt; {
self.headers.remove(key)
pub fn remove(&amp;mut self, key: impl AsRef&lt;str&gt;) -&gt; Option&lt;String&gt; {
self.headers
.remove(key.as_ref())
.map(|h| h.as_str().to_string())
}

/// Appends a value to a given key
Expand All @@ -676,6 +678,9 @@ <h4 id="proposed-implementation"><a class="header" href="#proposed-implementatio
/// If the component can be represented as a Cow&lt;'static, str&gt;, return it
fn into_maybe_static(self) -&gt; Result&lt;MaybeStatic, HttpError&gt;;

/// Return a string reference to this header
fn as_str(&amp;self) -&gt; Result&lt;&amp;str, HttpError&gt;;

/// If a component is already internally represented as a `http02x::HeaderName`, return it
fn repr_as_http02x_header_name(self) -&gt; Result&lt;http0::HeaderName, Self&gt;
where
Expand All @@ -689,18 +694,30 @@ <h4 id="proposed-implementation"><a class="header" href="#proposed-implementatio
fn into_maybe_static(self) -&gt; Result&lt;MaybeStatic, HttpError&gt; {
Ok(Cow::Borrowed(self))
}

fn as_str(&amp;self) -&gt; Result&lt;&amp;str, HttpError&gt; {
Ok(self)
}
}

impl AsHeaderComponent for String {
fn into_maybe_static(self) -&gt; Result&lt;MaybeStatic, HttpError&gt; {
Ok(Cow::Owned(self))
}

fn as_str(&amp;self) -&gt; Result&lt;&amp;str, HttpError&gt; {
Ok(self)
}
}

impl AsHeaderComponent for Cow&lt;'static, str&gt; {
fn into_maybe_static(self) -&gt; Result&lt;MaybeStatic, HttpError&gt; {
Ok(self)
}

fn as_str(&amp;self) -&gt; Result&lt;&amp;str, HttpError&gt; {
Ok(self.as_ref())
}
}

impl AsHeaderComponent for http0::HeaderValue {
Expand All @@ -711,13 +728,21 @@ <h4 id="proposed-implementation"><a class="header" href="#proposed-implementatio
.to_string(),
))
}

fn as_str(&amp;self) -&gt; Result&lt;&amp;str, HttpError&gt; {
std::str::from_utf8(self.as_bytes()).map_err(HttpError::header_was_not_a_string)
}
}

impl AsHeaderComponent for http0::HeaderName {
fn into_maybe_static(self) -&gt; Result&lt;MaybeStatic, HttpError&gt; {
Ok(self.to_string().into())
}

fn as_str(&amp;self) -&gt; Result&lt;&amp;str, HttpError&gt; {
Ok(self.as_ref())
}

fn repr_as_http02x_header_name(self) -&gt; Result&lt;http0::HeaderName, Self&gt;
where
Self: Sized,
Expand Down Expand Up @@ -865,7 +890,7 @@ <h4 id="proposed-implementation"><a class="header" href="#proposed-implementatio
#[cfg(test)]
mod test {
use crate::client::orchestrator::HttpRequest;
use aws_smithy_http::body::SdkBody;
use aws_smithy_types::body::SdkBody;
use http::header::{AUTHORIZATION, CONTENT_LENGTH};
use http::{HeaderValue, Uri};

Expand Down
2 changes: 1 addition & 1 deletion design/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion design/searchindex.json

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions design/server/anatomy.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,25 +207,28 @@ <h1 id="the-anatomy-of-a-service"><a class="header" href="#the-anatomy-of-a-serv
}
</code></pre>
<p>Smithy Rust will use this model to produce the following API:</p>
<pre><pre class="playground"><code class="language-rust edition2021"><span class="boring">#![allow(unused)]
<pre><pre class="playground"><code class="language-rust no_run edition2021"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span><span class="boring">extern crate pokemon_service_server_sdk;
</span><span class="boring">extern crate aws_smithy_http_server;
</span><span class="boring">use pokemon_service_server_sdk::{input::*, output::*, error::*, operation_shape::*, PokemonService};
</span><span class="boring">use aws_smithy_http_server::protocol::rest_json_1::{RestJson1, router::RestRouter};
</span><span class="boring">use aws_smithy_http_server::routing::{Route, RoutingService};
</span><span class="boring">use pokemon_service_server_sdk::{input::*, output::*, error::*, operation_shape::*, PokemonServiceConfig, PokemonService};
</span>// A handler for the `GetPokemonSpecies` operation (the `PokemonSpecies` resource).
async fn get_pokemon_species(input: GetPokemonSpeciesInput) -&gt; Result&lt;GetPokemonSpeciesOutput, GetPokemonSpeciesError&gt; {
todo!()
}

let config = PokemonServiceConfig::builder().build();

// Use the service builder to create `PokemonService`.
let pokemon_service = PokemonService::builder_without_plugins()
let pokemon_service = PokemonService::builder(config)
// Pass the handler directly to the service builder...
.get_pokemon_species(get_pokemon_species)
/* other operation setters */
.build()
<span class="boring"> ; Result::&lt;(), ()&gt;::Ok(())
</span> .expect(&quot;failed to create an instance of the Pokémon service&quot;);
<span class="boring">let pokemon_service: Result&lt;PokemonService&lt;aws_smithy_http_server::routing::Route&gt;, _&gt; = pokemon_service;
.expect(&quot;failed to create an instance of the Pokémon service&quot;);
<span class="boring">let pokemon_service: PokemonService&lt;RoutingService&lt;RestRouter&lt;Route&gt;, RestJson1&gt;&gt; = pokemon_service;
</span><span class="boring">}</span></code></pre></pre>
<h2 id="operations"><a class="header" href="#operations">Operations</a></h2>
<p>A <a href="https://awslabs.github.io/smithy/2.0/spec/service-types.html#operation">Smithy Operation</a> specifies the input, output, and possible errors of an API operation. One might characterize a Smithy Operation as syntax for specifying a function type.</p>
Expand Down Expand Up @@ -581,7 +584,9 @@ <h2 id="plugins"><a class="header" href="#plugins">Plugins</a></h2>
}
S --&gt; [*]: HTTP Response
</pre>
<p>The service builder API requires plugins to be specified upfront - they must be passed as an argument to <code>builder_with_plugins</code> and cannot be modified afterwards.</p>
<p>The service builder API requires plugins to be specified upfront - they must be
registered in the config object, which is passed as an argument to <code>builder</code>.
Plugins cannot be modified afterwards.</p>
<p>You might find yourself wanting to apply <em>multiple</em> plugins to your service.
This can be accommodated via [<code>HttpPlugins</code>] and [<code>ModelPlugins</code>].</p>
<pre><pre class="playground"><code class="language-rust edition2021"><span class="boring">#![allow(unused)]
Expand Down Expand Up @@ -622,7 +627,7 @@ <h2 id="plugins"><a class="header" href="#plugins">Plugins</a></h2>
<h2 id="builders"><a class="header" href="#builders">Builders</a></h2>
<p>The service builder is the primary public API, generated for every <a href="https://awslabs.github.io/smithy/2.0/spec/service-types.html">Smithy Service</a>.
At a high-level, the service builder takes as input a function for each Smithy Operation and returns a single HTTP service. The signature of each function, also known as <em>handlers</em>, must match the constraints of the corresponding Smithy model.</p>
<p>You can create an instance of a service builder by calling either <code>builder_without_plugins</code> or <code>builder_with_plugins</code> on the corresponding service struct.</p>
<p>You can create an instance of a service builder by calling <code>builder</code> on the corresponding service struct.</p>
<pre><pre class="playground"><code class="language-rust edition2021"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span><span class="boring">extern crate aws_smithy_http_server;
Expand Down
9 changes: 6 additions & 3 deletions design/server/instrumentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,18 @@ <h2 id="spans-over-the-requestresponse-lifecycle"><a class="header" href="#spans
instrumentation::InstrumentExt,
plugin::{IdentityPlugin, HttpPlugins}
};
use pokemon_service_server_sdk::PokemonService;
<span class="boring">use aws_smithy_http_server::protocol::rest_json_1::{RestJson1, router::RestRouter};
</span><span class="boring">use aws_smithy_http_server::routing::{Route, RoutingService};
</span>use pokemon_service_server_sdk::{PokemonServiceConfig, PokemonService};

let http_plugins = HttpPlugins::new().instrument();
let app = PokemonService::builder_with_plugins(http_plugins, IdentityPlugin)
let config = PokemonServiceConfig::builder().http_plugin(http_plugins).build();
let app = PokemonService::builder(config)
.get_pokemon_species(handler)
/* ... */
.build()
.unwrap();
<span class="boring">let app: PokemonService&lt;aws_smithy_http_server::routing::Route&gt; = app;
<span class="boring">let app: PokemonService&lt;RoutingService&lt;RestRouter&lt;Route&gt;, RestJson1&gt;&gt; = app;
</span><span class="boring">}</span></code></pre></pre>
<!-- TODO: Link to it when the logging module is no longer `#[doc(hidden)]` -->
<h3 id="example"><a class="header" href="#example">Example</a></h3>
Expand Down
Loading

0 comments on commit 9056936

Please sign in to comment.