"Effortless API Integration: SDK Generation as Best Practise", Nikita Galkin
fwdays
222 views
33 slides
Oct 19, 2024
Slide 1 of 33
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
About This Presentation
Many developers create a separate layer for working with APIs, but Nikita believes that this approach is inefficient — it is better to generate code from your API contract. The talk will cover the following topics: how does SDK differ from API, and why is SDK preferable for development? How can yo...
Many developers create a separate layer for working with APIs, but Nikita believes that this approach is inefficient — it is better to generate code from your API contract. The talk will cover the following topics: how does SDK differ from API, and why is SDK preferable for development? How can you automatically generate an SDK for Swagger and GraphQL? What should you do if you don’t have an API contract? And finally, why is it important for backend developers to understand React? The talk will help optimize development processes and simplify team interactions, making working with APIs more predictable and convenient.
Size: 1.58 MB
Language: en
Added: Oct 19, 2024
Slides: 33 pages
Slide Content
FRACTIONAL
AGENDA
Agenda 0
1.API Integration Pain
2.SDK vs API
3.Code generation for GraphQL API
4.Code generation for REST API
5.No API specifications ??????
6.One more reason to know React
API
INTEGRATION
PAIN
The pain 1 Interview question
Can you walk me through the best practices for
fetching and handling API data in a React
application? Specifically, what steps would you
take to ensure the solution is efficient,
maintainable, and user-friendly?
The pain 1 Typical Steps
1.?????? Create API Client
2.?????? Define Types for Input and Output Payload
3.?????? Validate Input and Output Data (e.g., using Zod or Joi)
4.?????? Transform Data if Required
5.⚙ Create the Hook with State Management
and Error Handling
6.⏹ Use AbortController for Cleanup
7.?????? Add Retry Logic for Network Errors
8.⏳ Add Loading Skeletons for UX Improvement
9.?????? Manage Cache for Performance Optimization
The pain 1 Typical solution
1.Fetch API
2.Axios (Axios-Retry)
3.RTK Query (Redux Toolkit Query)
4.React Query (TanStack Query)
5.Apollo Client
SDK vs API 2 API contract
API Contract (e.g., OpenAPI, RAML, Postman
Collections, GraphQL Schemas) describes:
●Endpoints
●Request/response models
●Authentication methods
SDK vs API 2 API contract
Company API Specification
SDK Languages
AWS
Smithy, OpenAPI JavaScript, Python, Java, Go,
Ruby, .NET, etc.
Azure
OpenAPI, OData Python, JavaScript, .NET, Go,
Java, etc.
Google Cloud
Discovery Document,
Protobuf, OpenAPI
Python, JavaScript, Java, Go,
Ruby, etc.
Stripe
OpenAPI JavaScript, Python, PHP,
Ruby, Java, .NET, Go
SDK vs API 2 SDK generation
1.Parse API Contract: Extract endpoints, models, and
data types.
2.Generate Code: Create SDK with models and API
wrappers.
3.Add Utilities: Authentication, retries, error handling,
logging, etc.
4.Documentation: Include inline API docs (e.g.,
JSDoc).
SDK vs API 2 Main ideas
●The API should have a contract defined as a
specification.
●Client integration code should be generated
from that specification.
●Code generation provides clear boundary
between integration code and application
code.
No specification 5 API Design First
1.Design-first means defining the API contract before
implementation.
2.Focuses on collaboration between teams (frontend,
backend, and stakeholders).
3.API contract serves as the single source of truth.
No specification 5 API Design First
•Faster Development: Parallel work for frontend and backend
teams.
•Clear Expectations: Ensures all stakeholders agree on API
behavior early.
•Improved Quality: Reduces misunderstandings and
mismatched expectations.
•Easier Testing: Enables API mocking and automated testing.
•Better Documentation: The API contract generates
documentation automatically.
No specification 5 API Design First
•Faster Development: Parallel work for frontend and backend
teams.
•Clear Expectations: Ensures all stakeholders agree on API
behavior early.
•Improved Quality: Reduces misunderstandings and
mismatched expectations.
•Easier Testing: Enables API mocking and automated testing.
•Better Documentation: The API contract generates
documentation automatically.
No specification 5 TypeSpec
No specification 4 TypeSpec
One more
reason to know
React
Alloy 6 TypeSpec
SDK vs API 6 Main ideas
●The API should have a contract defined as a
specification.
●Client integration code should be generated
from that specification.
●Code generation provides clear boundary
between integration code and application
code.