InterviewBuddy
All interview questions

What should an API do with invalid input?

Intermediate

Answer

Reject invalid input at the boundary with a useful client error, and keep database constraints as a final integrity guard. Distinguish malformed requests from conflicts and unexpected server failures.

Explanation

Validation should cover types, lengths, allowed values, and relationships. Do not echo sensitive data in error messages.

Example

400: malformed input; 409: conflicting unique value