I'm building a RESTful API using Node/Express4 and so far I've been successful. However, I'm not sure where to implement URL data validation - should the router script block invalid URI requests or should it send the controller the invalid data for it to send back an error?
The expected URI is as in the following example:
And it should return me a JSON array of posts in Year/Month/Day.
What I want is to implement a way to prevent an invalid date request from being sent to the database query, for example
Should return an error.
My doubt is whether it is more appropriate for the router to validate the year in the example (4 digits, only numeric characters) or if it should send '20170105' to the controller and have it parse the URI and throw an error back at the client.
Is there a recommended way or does either work equally well from a structural point of view?