Open aulneau opened 3 weeks ago
I'm with you @aulneau. I even created another API client just to provide myself with a friendlier API.
Perhaps it would be worthwhile to look into trpc or Elysia for the Stacks API. Elysia can also use TypeBox, supports typing of both params and body, and has OpenAPI plugins.
By inferring client types directly from the API definition, these tools are able to provide great DX. No need to wrangle a typed client together from the OpenAPI spec of the original typed API definition.
Hi @aulneau, the error schema isn't defined for many of the routes which is why you're seeing the error: never
type issue. The route definition here needs a status 4xx response schema defined: https://github.com/hirosystems/stacks-blockchain-api/blob/f0176a038b3c4fde35195bbfbf9b6d8d5504c9bb/src/api/routes/bns/addresses.ts#L37-L51
For now you can check the request status like:
Here's an example of a route with correct error status schemas defined: https://github.com/hirosystems/stacks-blockchain-api/blob/f0176a038b3c4fde35195bbfbf9b6d8d5504c9bb/src/api/routes/search.ts#L277-L289
Hey all :)
The new openapi-fetch based client is pretty hard and confusing to use, could you add some basic documentation? 🙏
Additionally, I'm having a really hard time getting types to work correctly, I have to wrangle them pretty explicitly:
Let me know if I'm missing anything or doing this incorrectly btw!
Thanks!!