...

/

Solution: Unify HTTP Client Responses

Solution: Unify HTTP Client Responses

Normalize the output of two different HTTP clients so they both return { body, statusCode }.

We'll cover the following...

Solution explanation

  • Lines 2–12: We simulate two HTTP clients:

    • rawHttpClient.get(url) returns only a string (the raw body).

    • structuredHttpClient.get(url) returns an object with { data, status }.

    • Both have the same method name (get) but incompatible response shapes.

  • Lines 15–17: The HttpClientAdapter constructor accepts a client instance.

    • It stores the client reference.

    • This allows the same adapter class ...