Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SDK Secrets: Unlocking API Magic

Avatar for Ehi Enabs Ehi Enabs
October 19, 2024

SDK Secrets: Unlocking API Magic

In this exploration of SDK development with Go, we will cover the “hows” and “whys” that every developer should know when building an SDK for their APIs. We will explore the foundational principles and best practices for building efficient, user-friendly, and robust SDKs. We will cover seamless API integrations for improved programmatic functionality. We will cover the basics, core design principles and implementation strategies you can leverage to ensure a successful SDK for your APIs.

Avatar for Ehi Enabs

Ehi Enabs

October 19, 2024

More Decks by Ehi Enabs

Other Decks in Technology

Transcript

  1. “The craft of programming begins with empathy, not formatting or

    languages or tools or algorithms or data structures.” - Kent Beck Creator of “Extreme Programming” Welcome!
  2. My name is Ehi Enabulele. I am a Software Engineer

    at the Wikimedia Foundation. My primary focus is cloud-native and backend engineering. • I work with the Enterprise Team where I help build and manage resilient APIs for high volume and commercial reusers. • I am passionate about knowledge equity and accessibility. As well as the tools, social and economic means for achieving these goals. Ehi Enabulele Software Engineer, WMF Find me on Twitter at @ehienabs , LinkedIn:Ehi Enabs and Email: [email protected]
  3. AGENDA 01 APIs and SDKs What are they and why

    do we need them? 02 Building an SDK: Operations. Let’s start from the very beginning. 03 Building an SDK: Efficiency Better. Faster. Stronger. 04 Building an SDK: Empathy Taking care of you and everyone else.
  4. • Application Programming Interface. • They allow different software systems

    to communicate with each other by defining a set of rules and protocols. • APIs define the methods and data structures that applications can use to request and exchange information. • They enable developers to access specific features or data of an application without needing to understand its internal workings APIs
  5. • Software Development Toolkit • A collection of software tools,

    libraries, documentation, code samples, and guides. • Usually provided by vendors to enable developers to build applications using their services. • Allowing developers to integrate complex functionalities without starting from scratch. • Help abstract the underlying complexity and internal working of vendor’s services. SDKs
  6. func NewClient(ops ...func(clt *Client)) API { clt := &Client{ HTTPClient:

    &http.Client{}, BaseURL: "gopherconafricamart.com", DownloadConcurrency: 10, } for _, opt := range ops { opt(clt) } return clt }
  7. type ItemsDownloader interface { DownloadItems(ctx context.Context, nme string, req *Request)

    error } func (c *Client) DownloadItems(ctx context.Context, nme string, wsk io.WriteSeeker) error { return c.downloadObjects(ctx, fmt.Sprintf("items/%s/download", nme), wsk) }
  8. func (c *Client) downloadObjects (ctx context.Context, requests []*Request, names []string)

    ([]interface{}, error) { objs := make([]interface{}, len(requests)) for i, req := range requests { var val interface{} err := c.getObject(ctx, req, names[i], &val) objs[i] = val } return objs, nil }
  9. func (c *Client) downloadObjects(ctx context.Context, requests []*Request, names []string) ([]interface{},

    error) { results := make([]interface{}, len(requests)) for i, req := range requests { var val interface{} err := c.getObject(ctx, req, names[i], &val) if err != nil { return nil, fmt.Errorf("error downloading object %s: %w", names[i], err) } results[i] = val } return results, nil }
  10. func (c *Client) downloadObjects(ctx context.Context, requests []*Request, names []string) ([]interface{},

    error) { results := make([]interface{}, len(requests)) ... for i, req := range requests { go func(i int, req *Request, name string) { var val interface{} err := c.getObject(ctx, req, name, &val) results[i] = val }(i, req, names[i]) } ... return results, nil }
  11. func (c *Client) downloadObjects (ctx context.Context, requests []*Request, names []string)

    ([]interface{}, error) { results := make([]interface{}, len(requests)) var wg sync.WaitGroup for i, req := range requests { wg.Add(1) go func(i int, req *Request, name string) { defer wg.Done() var val interface{} err := c.getObject(ctx, req, name, &val) results[i] = val }(i, req, names[i]) } wg.Wait() return results, nil } }
  12. “You think you just fell out of a coconut tree?

    You exist in the context of all in which you live and what came before you” - VP. Kamala Harris
  13. type Location struct { Country string `json:"country,omitempty"` City string `json:"city,omitempty"`

    } type User struct { Name string `json:"name,omitempty"` Group string `json:"group,omitempty"` Tier int `json:"tier,omitempty"` Location Location `json:"location,omitempty"` }
  14. type ProfileDownloader interface { DownloadProfile(ctx context.Context, nme string, req *Request)

    error } func (c *Client) DownloadProfile(ctx context.Context, nme string, wsk io.WriteSeeker) error { return c.downloadObjects(ctx, fmt.Sprintf("profile/%s/download", nme), wsk) }