I have a scenario where I can take a student Id as input via a part variable and return some data back as JSON objects where JavaScript handles the response as a part of AJAX call.
Suppose the method is called like:
/student/{studentId}
where studentId is a path variable in Spring MVC web service declaration. Now for requests to /student, the front end gets a "404 Not Found" error.
Where should this be handled on the front end or I should create a new method and map it to the /student call and then throw a custom exception?
1 Answer 1
Front-End should validate user input based on requirements of the back-end, so if a route need a primary key or any other parameter, front-end should check and ask the user for that parameter and call API, as defined in it, 's the route, always with id
,
of the curse in back-end this should consider that if no id
provided, return a proper error.
/students/<id>
(note plural form), and for a GET to/students
to provide a list of all students. The method of the front end should probably throw an error without even calling the backend if it isn't given an ID to use.