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

Yes! You should provide a client library for your API!

Daniel Azuma
November 13, 2018

Yes! You should provide a client library for your API!

Presentation by Daniel Azuma at RubyConf 2018. Discusses API client libraries, what they should do, why they are useful, and how they can be created and maintained at scale. More information at http://daniel-azuma.com/rubyconf2018

Daniel Azuma

November 13, 2018
Tweet

More Decks by Daniel Azuma

Other Decks in Programming

Transcript

  1. Yes!
    You should provide
    a client library
    for your API!
    Daniel Azuma
    Nov 13, 2018

    View Slide

  2. Source: https://pixabay.com/en/hands-raised-raised-hands-arms-up-1768845/
    License: CC0 (https://creativecommons.org/publicdomain/zero/1.0/)

    View Slide

  3. API Client Library

    View Slide

  4. API Client Library
    A Ruby gem

    providing a nice Ruby interface

    for calling a network API

    View Slide

  5. View Slide

  6. View Slide

  7. Daniel Azuma
    @danielazuma

    http:/
    /daniel-azuma.com/

    View Slide

  8. View Slide

  9. .rb .py .js .go .php
    .rb .py .js .go .php
    .rb .py .js .go .php
    .rb .py .js .go .php


    >10 languages
    >250 services

    View Slide

  10. Is it worth it?

    View Slide

  11. Source: https://pixabay.com/en/baby-boy-child-childhood-computer-84627/
    License: CC0 (https://creativecommons.org/publicdomain/zero/1.0/)

    View Slide

  12. View Slide

  13. APIs are hard

    View Slide

  14. Auth

    View Slide

  15. Retry

    View Slide

  16. Caching

    View Slide

  17. Auth

    Retry

    Caching

    Quotas

    Error Handling

    Pagination

    Instrumentation

    Long-running Operations

    Versioning

    etc…

    View Slide

  18. API > HTTP

    View Slide

  19. View Slide

  20. Know the protocol

    View Slide

  21. Client Example

    View Slide

  22. Stub Object
    Client Example

    View Slide

  23. Identity / auth
    Client Example

    View Slide

  24. Method calls
    Client Example

    View Slide

  25. Result objects
    Client Example

    View Slide

  26. no URLs

    no JSON

    no HTTP status
    Client Example

    View Slide

  27. no URLs

    no JSON

    no HTTP status

    no retry

    no caching
    Client Example

    View Slide

  28. DevX

    View Slide

  29. Use Ruby abstractions

    View Slide

  30. View Slide

  31. Use Ruby abstractions

    Handle errors

    View Slide

  32. Use Ruby abstractions

    Handle errors

    Improve safety/security

    View Slide

  33. Use Ruby abstractions

    Handle errors

    Improve safety/security

    Improve performance

    View Slide

  34. log entry send request
    user app client library logging service
    receive response
    return
    log entry send request
    receive response
    return

    View Slide

  35. queue queue
    log entries
    log entries
    send batch
    send batch
    user app client library logging service

    View Slide

  36. Use Ruby abstractions

    Handle errors

    Improve safety/security

    Improve performance

    Provide instrumentation

    View Slide

  37. Use Ruby abstractions

    Handle errors

    Improve safety/security

    Improve performance

    Provide instrumentation

    View Slide

  38. .rb .py .js .go .php
    .rb .py .js .go .php
    .rb .py .js .go .php
    .rb .py .js .go .php


    >10 languages
    >250 services

    View Slide

  39. Interface Description Language

    View Slide

  40. Interface Description Language
    Source: https://pixabay.com/en/book-geek-glasses-read-robot-1296590/
    License: CC0 (https://creativecommons.org/publicdomain/zero/1.0/)

    View Slide

  41. Interface Description Language
    Calls

    View Slide

  42. Interface Description Language
    Calls

    Parameters/results

    View Slide

  43. Interface Description Language
    Calls

    Parameters/results

    Data types

    View Slide

  44. Interface Description Language
    Calls

    Parameters/results

    Data types

    Properties

    View Slide

  45. Interface Description Language
    Calls

    Parameters/results

    Data types

    Properties

    Documentation

    View Slide

  46. WSDL

    View Slide

  47. SOAP

    View Slide

  48. https:/
    /openapis.org/

    View Slide

  49. .rb

    View Slide

  50. Metaprogramming

    View Slide

  51. IDL
    Client Library
    Metaprogramming
    Engine
    Generated
    Classes

    View Slide

  52. IDL
    Client Library
    Metaprogramming
    Engine
    Generated
    Classes

    View Slide

  53. Code generation

    View Slide

  54. IDL
    Code Generator
    Generator
    Engine
    Client Library
    Generated
    Ruby Files

    View Slide

  55. IDL
    Code Generator
    Generator
    Engine
    Client Library
    Reference
    Documentation
    Server Skeleton
    Automated Tests

    View Slide

  56. View Slide

  57. How do I get started?
    +

    View Slide

  58. How do I get started?
    +
    Choose a spec standard

    View Slide

  59. Choose a spec standard
    How do I get started?
    +
    Write an API description

    View Slide

  60. Choose a spec standard
    How do I get started?
    +
    Write an API description
    Invoke an open source generator

    View Slide

  61. Choose a spec standard
    How do I get started?
    +
    Write an API description
    Invoke an open source generator
    Customize the generator

    View Slide

  62. Why to write a client library

    View Slide

  63. Why to write a client library

    What should go in a client library

    View Slide

  64. Why to write a client library

    What should go in a client library

    How to write scalable client libraries

    View Slide

  65. Why to write a client library

    What should go in a client library

    How to write scalable client libraries

    View Slide

  66. Yes!
    You should provide
    a client library
    for your API!
    ,

    View Slide

  67. Yes!
    You should provide
    a client library
    for your API!
    https:/
    /daniel-azuma.com/rubyconf2018

    View Slide