-
Notifications
You must be signed in to change notification settings - Fork 6
Types
Matt Muller edited this page Apr 12, 2024
·
6 revisions
Types are light-weight classes that contain shape data. Types are built from params on input and populated by service responses on output. Types have a 1:1 mapping to Smithy structure shapes, enum shapes, and union shapes.
structure HighScoreAttributes {
id: String,
game: String,
score: Integer
}
Types are automatically constructed using the Params module when a hash of params are passed into the Client's operation. Optionally, Types can be constructed manually and passed into the Client's operation as params instead. Types are always returned by Client operations when data is returned from the service.
client = HighScoreService::Client.new(endpoint: 'http://127.0.0.1:3000')
# => #<HighScoreService::Client ... >
output = client.get_high_score(id: '1')
# => #<Hearth::Output ... >
# Optional, preference
get_high_score_input = HighScoreService::Types::GetHighScoreInput.new(id: '1')
output = client.get_high_score(get_high_score_input)
# => #<Hearth::Output ... >
output.data.class
# => HighScoreService::Types::GetHighScoreOutput(keyword_init: true)
output.data.high_score.class
# => HighScoreService::Types::HighScoreAttributes(keyword_init: true)
Types have a to_h
utility method which works with nested Types:
output.data.to_h
# => {:high_score=>{:id=>"1", :game=>"Frogger", :score=>9001}}