Implement buildApiClient(fetch, baseUrl)
Write buildApiClient(fetch, baseUrl) that returns a small client object with .get(path) and .post(path, body) methods, both of which:
- Request
baseUrl + path. postsendsbodyJSON-encoded, with aContent-Type: application/jsonheader.- Throw an error mentioning the status code on any non-2xx response (same rule as
fetchJson). - Return the parsed JSON body on success.
const client = buildApiClient(fetch, "https://api.example.com");
await client.get("/users/1");
await client.post("/users", { name: "Ada" });