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

JavaScript API Proxy Pattern

JavaScript API Proxy Pattern

The presentation describes what is API proxy pattern, the problem it solves and how to implement it. It also showcases how it makes testing easier and the future of ES6 Proxies.

Allan Chua

March 13, 2019
Tweet

More Decks by Allan Chua

Other Decks in Technology

Transcript

  1. API Proxy Pattern:
    Reusable and Mockable
    API Calls
    Allan A. Chua
    https://www.pogsdotnet.com

    View Slide

  2. https://bit.ly/2HhiRVv
    GITHUB DEMO LINK

    View Slide

  3. https://bit.ly/2TH1mDM
    Slide Deck Link

    View Slide

  4. • What is Proxy Design Pattern
    • Problems it solves
    • How to implement
    • How to improve
    • How it makes testing easy
    • The Future
    Agenda

    View Slide

  5. • Provide a surrogate or placeholder for another object to
    control access to it.
    • Use an extra level of indirection to support distributed,
    controlled, or intelligent access.
    • Add a wrapper and delegation to protect the real
    component from undue complexity.
    What is Proxy Pattern

    View Slide

  6. How it Looks Like
    Object
    Consumer
    Proxy
    Encapsulates access
    management

    View Slide

  7. How it Looks Like

    View Slide

  8. How it Looks Like

    View Slide

  9. Why its perfect for API Calls
    API Consumer
    Proxy
    Encapsulates protocol and framework used to call API

    View Slide

  10. Bad API Reuse
    Consumer A Consumer B Consumer C
    API A
    API B
    API A
    API B
    API B

    View Slide

  11. Good API Reuse
    Consumer A Consumer B Consumer C
    API B
    API A
    Proxy A Proxy B

    View Slide

  12. Easy and Predictable Testing
    Consumer A
    API A
    Proxy A
    Mock Proxy
    Consumer Testing

    View Slide

  13. ES6 Proxies

    View Slide

  14. View Slide