[HN Gopher] Ts-Rest: TypeScript Contracts for REST APIs with Bui...
___________________________________________________________________
Ts-Rest: TypeScript Contracts for REST APIs with Built-In Zod
Validation
Author : cassepipe
Score : 12 points
Date : 2025-04-14 17:17 UTC (5 hours ago)
(HTM) web link (ts-rest.com)
(TXT) w3m dump (ts-rest.com)
| SebastianKra wrote:
| The contract-first design and return to REST seem like solid
| improvements over trpc.
|
| Lately, I've been thinking about what would be the simplest way
| to typecheck a rest api. I wonder if...
|
| - ...it would make sense to define endpoints in isolation, rather
| than one big router object. Large / recursive types have bad
| performance, especially when mixed with zod. Isolated contract
| definitions would prevent statically checking for path conflicts
| though.
|
| - ...a composition-based api would be better than a wrapper to
| minimize the API surface: const getPostById =
| endpoint(/* */) // client const postResponse
| = fetch(getRequest(getPostById, 123)) const post =
| getResponseData(getPostsById, postResponse)
| cassepipe wrote:
| Comparison to tRPC discussed here : https://ts-
| rest.com/docs/comparisons/rpc-comparison
___________________________________________________________________
(page generated 2025-04-14 23:01 UTC)