Fetch API types; Response.json() generics
Use the Fetch API with correct types, and Response.json () generics to safely parse JSON payloads.
Intro
Goal: Call APIs with fetch, handle responses safely, and use generics with Response.json().
Basic fetch
fetch returns a Promise<Response>. Use res.text() for plain text bodies.
async function getText() {
const res = await fetch("/hello.txt");
const text = await res.text();
console.log(text);
}All lessons in this course
- Fetch API types; Response.json() generics
- Runtime validation with zod (intro)