Skip to content

Endpoints

Juli Tera edited this page Apr 12, 2024 · 3 revisions

Endpoints and Endpoint Providers are mechanisms for configuring and resolving endpoints. Endpoint Providers have a 1:1 mapping to Smithy service shapes.

Endpoint Provider

An Endpoint Provider can be any class responding to resolve(params). The Endpoint Provider responsible for returning a Hearth::EndpointRules::Endpoint object containing the uri, and optionally a list of auth scheme overrides and additional headers to use. The Endpoint Provider is code generated from the Endpoint Rules. If no Endpoint Rules are present, a default ruleset which returns the static configured Endpoint will be used. The Endpoint rules are an implementation detail.

class StaticEndpointProvider
  def resolve(params)
    # custom logic - perhaps check for beta stack
    uri = URI('http://127.0.0.1:9001')
    Hearth::EndpointRules::Endpoint.new(uri: uri)
  end
end
# => :resolve

HighScoreService::Client.new(
  endpoint: 'http://127.0.0.1:3000',
  endpoint_provider: StaticEndpointProvider.new
)
# => #<HighScoreService::Client ... >

client.list_high_scores
# <Makes request against port 9001>
# => #<Hearth::Output @data=... >

Endpoints and Auth

The Auth Resolver is responsible for resolving the auth scheme. Endpoint resolution only augments and modifies the resolved auth scheme signer and identity properties. For example, changing the region used for signing in SigV4.