Building Strongly Typed REST Clients with Typescript
summary
Builds a type-safe client for a book-catalog REST API (paths /book and /book/{bookId} supporting GET/POST/PUT and GET/DELETE) using TypeScript template literal types and a recursive path-parameter extractor to turn URL templates into positional function parameters. Maps each path to operation-specific request and response types (status code string literals, body shapes, headers), uses tuple/rest types for required params, and demonstrates working editor completions and narrowing so callers get correct payload fields and precise response types.
AI-written summary · about
chapters (15)
- 0:00Introduction to talk
- 0:43REST API overview
- 1:47Setting up the client
- 3:41Limiting path options
- 5:33Detecting path parameters
- 9:29Handling required parameters
- 13:28Finalizing path function
- 15:23Adding API methods
- 17:10Defining response types
- 19:38Implementing response types
- 21:05Exploring response shapes
- 22:52Error handling with types
- 23:57Adding input parameters
- 25:22Building request payload
- 25:46Demo and conclusion
related talks
30mTypeScript: Gradual, Structural, Dynamic, Static
33mTypeScript for APIs
34mGenerating Types without climbing a tree
27mTake a rest from REST
29mCrafting Reliable and Testable Code with TypeScript
35mTypeScript Gymnastics: Why Are They So Powerful for You?
20mREST API Validation in a Typescript front-end
01h 01mDeconstructing TypeScript’s Type System
