News for hackers. Stuff that matters.
Re:Zod: TypeScript-first schema validation with static type ... by aleksiy123 on Wednesday October 09, 2024 @02:07PM (#41790912)
Does anyone have a nice combination of tooling for typed handlers + client generation.

Thinking maybe Zod + Zod open API.

Really looking to replicate similar spec first workflow similar to protobuf services.

https://typespec.io/ also looks promising but seems early.

Re:Zod: TypeScript-first schema validation with static type ... by mnahkies on Wednesday October 09, 2024 @02:11PM (#41790949)
My tool https://openapi-code-generator.nahkies.co.nz/overview/about generates typed handlers based around koa (routing, req/res validation using zod) from openapi 3, as well as typed clients with optional zod validation using fetch/axios.

It also supports typespec using their transpilation to openapi 3 tooling

Re:Zod: TypeScript-first schema validation with static type ... by bjacobso on Wednesday October 09, 2024 @02:10PM (#41790939)
I think you are looking for https://ts-rest.com/
Re:Zod: TypeScript-first schema validation with static type ... by kaoD on Wednesday October 09, 2024 @02:15PM (#41790984)
Nice. I'm looking to migrate away from a legacy custom framework over Express and this could help.

If someone has tried both, can anyone share how it compares with tRPC[0]?

[0] https://trpc.io/

Re:Zod: TypeScript-first schema validation with static type ... by bjacobso on Wednesday October 09, 2024 @02:21PM (#41791036)
From my understanding trpc is very similar, however, the rpc mechanism is not a standard. ts-rest produces openapi schemas and speaks REST over http, as well as a typed client.

That being said, I am actually slowly migrating off ts-rest and adopting @effect/schema and @effect/platform/HttpApi, I foresee this being the direction the typescript ecosystem heads in over the next few years. However, the APIs are not stable yet and it has a bit of a learning curve, so would not adopt lightly

Re:Zod: TypeScript-first schema validation with static type ... by AWebOfBrown on Wednesday October 09, 2024 @05:52PM (#41793078)
I really wanted to adopt tRPC but the deal breaker was it being opinionated on status codes without allowing configurability. Because I needed to meet an existing API spec, that meant ts-rest was a better option. I think there's an aditional option with a native spec generator in frameworks like Hono, and maybe Elysia.
Re:Zod: TypeScript-first schema validation with static type ... by simplesagar on Monday October 14, 2024 @03:21AM (#41835069)
Check out https://www.speakeasy.com/. We generate fully type-safe SDK from OpenAPI and for our TS offering we delegate the type checking to Zod.