Course lesson

Validate HTTP API Response with zod, fetch and axios

In this lesson we learn that TypeScript cannot guarantee correct shapes of responses. That's due to TS performing checks in compile-time, while the response will be availbale in runtime - when TS doesn't exist anymore.

Duration
9 min
Access
Included
Transcript
Needs source

In this lesson we learn that TypeScript cannot guarantee correct shapes of responses. That's due to TS performing checks in compile-time, while the response will be availbale in runtime - when TS doesn't exist anymore.

In some situations, such as HTTP requests, runtime type checks such as zod are essential for providing quick feedback around data-related errors.

Understand where are the possible mistakes to make while using TypeScript with HTTP calls. Use fetch and axios along with zod schema checks.

Also, note that similar mistakes or mistakes could happen while using web storage (e.g. localStorage)