...
/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...
We'll cover the following...
Solution explanation
Lines 1–17: We define three interchangeable client classes:
RestClient,GraphQLClient, andSoapClient.Each implements a
.fetch()method, keeping the interface consistent for consumers.RestClientsimulates REST API calls,GraphQLClientrepresents query-based requests, andSoapClientmimics XML-style service interactions. ...