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:


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?

  • 3
    For a REST endpoint I'd expect /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.
    – jonrsharpe
    Dec 23 '18 at 10:49

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.