REST API validation - two short questions about validation

Posted by Loud_Wrangler1255@reddit | learnprogramming | View on Reddit | 17 comments

Hi! I'd like to ask you guys two questions about REST API validation that were bothering me for some time.

  1. Say I send a POST/PUT/PATCH request to "/resource/{resourceId}". Do I validate the Request DTO first or do I check if the "{resourceId}" even exists first?
  2. Say I send a Request DTO - here I validate the things that are inside - some of them are wrong so they're added to the list of errors that later will be returned in a single request. However, what about some other constraints such as "unique field" or "foreign key (id) that must exist"? Do I also check them and add them to the list of validation errors?

Thanks a lot for your time!