Skip to main content

Practice ยท 1 of 3

Guarded JSON Fetch

Write async function fetchJSON(url, fetchImpl) โ€” fetchImpl defaults to the real fetch (the tests inject a fake). It must: - throw new Error("HTTP " + status) when !res.ok - return the parsed JSON otherwise - expose method and headers when a body is sent: fetchJSON(url, fetchImpl, { method: "POST", body: value }) must call fetch with method, body: JSON.stringify(value), and Content-Type: application/json.

Difficulty: intermediate

Back to lesson: Practice: fetch & Pagination โ€” Practice