...

/

Solution: Build a Vendor-Agnostic API Client Factory

Solution: Build a Vendor-Agnostic API Client Factory

Use a string-to-class map in the factory to return the correct API client—no branching logic.

We'll cover the following...

Solution explanation

  • Lines 1–17: We define three interchangeable client classes: RestClient, GraphQLClient, and SoapClient.

    • Each implements a .fetch() method, keeping the interface consistent for consumers.

    • RestClient simulates REST API calls, GraphQLClient represents query-based requests, and SoapClient mimics XML-style service interactions. ...