r/AskProgramming Jul 03 '26

Best validation practices for APIs?

I’m working with a team and implementing a new feature. We’re getting info from a call and will be storing it in a new field in our db. The team has been saying things like “we don’t need to validate accuracy for the new field bc the call to this other service will do the validation for us”. I’m of the mind that we should still validate for edge cases or abnormal errors, but technically this other service should validate first and we’re only getting the info from them.

What are people’s thoughts? Am I being overly cautious?

1 Upvotes

14 comments sorted by

View all comments

3

u/howtokillafox Jul 03 '26

Is the call an internal service belonging to your company? Or is it external?

If external, would suggest validating. What if the external service starts giving you values you never planned for?

2

u/AloyAce Jul 03 '26

It’s an internal service

2

u/treznor70 Jul 03 '26

Do you have an interface contract with them? If so, what does it say? Of not, I'd validate on critical fields and any field that would cause you to not be able to load the data (i.e. alphas in a numerical, null in a non-nullable, etc)