I'm building a REST api which take some inputs like id,customer_id,firstname,lastname,contact,email,updated_time,created_time. Before processing these inputs, i have added validations to check if
- id and customer is number
- firstname is not a null and string,
- created and updated time are not null and empty string
- email id is in valid format
- contact field is number
- check for email and contact already exist in database
And few more validations also made. But it made the code redundant and reduced code readability and maintainability. Is it a good practice to include these much validations in a single api call?
Tried making a common structure for api response. But I want to produce different error response in each conditions.