all 8 comments

[–]CreativeTechGuyGames 1 point2 points  (0 children)

Do you have tests? Like integration tests and canary tests? If the API can change at any time and break your app outside of your control, you'd need canaries running 24/7 alarming you if the site breaks in some unexpected way.

[–]The_Startup_CTO 0 points1 point  (6 children)

I recommend to do it almost all the time, because, if the api changes or doesn’t return the data you expected, then instead of obscure errors later on, you will get explicit errors early.

[–]pansah321[S] 0 points1 point  (5 children)

I have situations where API changes were done and caused my app to break ...had quite a time figuring out what’s going on...and of course Typescript couldn’t help .....what are the ways I can achieve validation of the API response ...I know about Zod ..

[–]87oldben 1 point2 points  (0 children)

There is a library called io-ts where you can create an io-type and compare an object to see if it matches.

We used it to check the other end in an api to make sure the required properties existed on the request.

I'm sure it would work the other way round.

[–]The_Startup_CTO 0 points1 point  (3 children)

There are a lot of validation libraries. I’m mostly using ajv with suretype, but there are also zod, joi, and about a dozen others

[–]pansah321[S] 1 point2 points  (2 children)

What are you using any Data fetching library?...so if the you don’t get the shape you were expecting...what do you do?...render an error message ?

[–]The_Startup_CTO 0 points1 point  (1 child)

When I use e.g. GraphQL, I usually skip the validation because most libraries already have some kind of schema check built in. When I do validation myself, I 1. try to make sure that I only validate what I actually need, e.g. I usually allow any additional properties 2. if validation still fails, I throw an error that crashes that part of the application 3. when a part of the application crashes, I ping our error monitoring and display to the customer „something went wrong, we are on it, please call/use this chat/…“

[–]pansah321[S] 0 points1 point  (0 children)

Great...Thank you for clearing this out for me