Generating a custom Ruby SDK for your web service or Rails API using Smithy

g2nightmarescribd 160 views 74 slides May 28, 2024
Slide 1
Slide 1 of 74
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74

About This Presentation

Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn...


Slide Content

Generating a custom Ruby SDK for your web service or Rails API Matt Muller SDE @ AWS 1

Who am I? Example Use Case and Service Smithy Overview Using Smithy to model and generate an SDK Deep dive into SDK usage and components Final thoughts Agenda 2

Software Engineer @ AWS (AWS SDK for Ruby) Ruby advocate First time presenting (at a developer conference) First time in Japan 3 Who am I?

Let’s get started… 4

Use Case Scenario 5

Example Application 6 “High Score Service”

Create Rails API 7

Scaffolding 8

Migrate database 9

Run server 10

Call our API 11

Generating an SDK for your API in Smithy 12

What is Smithy? Smithy is a language for defining services and SDKs. 13

Features of Smithy 14 Protocol-agnostic Designed to evolve API governance Resource based Works for any programming languages Describe services running in any environment Works with any transport format Extended through traits Extensible meta-model Avoid breaking changes Customizable API standards Validation rules across all APIs Models are defined by resources and operations Rich information for model transformations

Installing smithy-cli 15

Modeling the High Score service 16

Writing the model 17 model/high-score- service.smithy

Writing the model (continued) 18 Map to CRUD controller actions!

Writing the model (continued) 19 high_scores_controller.rb in myapp

Writing the model (continued) 20

Writing the model (continued) 21 high_scores_controller.rb in myapp

Writing the model (continued) 22 seeds.rb in myapp

Writing smithy- build.json 23

Generating the SDK 24

What’s included? 25

Using the SDK 26

Using the SDK (continued) 27

Using the SDK (continued) 28

How does it work? 29

Benefits of a Smithy Ruby SDK Easy to use Rich features Highly extensible at runtime Code generated Bring your own protocol and integrations 30

Public Features 31

Client API entry point Accepts configuration Calls operations 32

Client (continued) 33

Config Configure options and components for your SDK Per-operation override of config 34

Config (continued) 35

Types Data containers for input and output 36

Types (continued) 37

Logging Standard Ruby Logger Debug SDK internals or wire logging 38

Logging (continued) 39

Errors Standard Ruby Exceptions Follows a hierarchy Modeled or unmodeled error handling 40

Errors (continued) 41

Errors (continued) 42 models/high-score- service.smithy models/ high_score.rb in myapp

Errors (continued) 43

Errors (continued) 44

HTTP Client Bring your own HTTP Client Includes a Net::HTTP default 45

HTTP Client (continued) 46

Retries Retry network errors Retryable modeled errors Custom retry strategy 47

Retries (continued) 48

Retries (continued) 49

Retries (continued) 50

Stubbing Mock responses for testing Does not use the network 51

Stubbing (continued) 52

Interceptors Lifecycle hooks into the SDK Modify input, output, request, or response 53

Interceptors (continued) 54

Interceptors (continued) 55

Plugins Distributable code that modifies config 56

Plugins (continued) 57

Waiters ”waits” (blocks) until some condition Uses polling on an interval basis 58

Waiters (continued) 59

Waiters (continued) 60

Paginators Paginated service calls Enumerators for both pages and items 61

Paginators (continued) 62

Paginators (continued) 63

Other features Modeled auth (Bearer, SigV4, HTTP basic/digest) Modeled and dynamic endpoint resolution DNS resolving hooks in the HTTP client Connection pooling Your next great idea  64

Diving deeper into internals … 65

Builders 66

Parsers 67

Validators 68

Params 69

Stubs 70

Middleware 71

Middleware (continued) 72

What do you think? Experimental Feedback welcomed! Backbone of a future version of AWS SDK for Ruby 73

Matt Muller GitHub: mullermp No other socials 74 Smithy Ruby https://github.com/smithy-lang/smithy-ruby Today’s Demo https://github.com/mullermp/rubykaigi2024