When using my API, the endpoint '/api/students'
will display all student names. If a req.query is input with a specific name, such as "John", the endpoint becomes '/api/students?name=John'
. I have implemented regex to ensure that only characters and spaces are allowed in the input:
const re = /^[a-zA-Z ]*$/;
if (!re.test(name)) {//error code
However, if a user accidentally inputs the endpoint as '/api/students?firstnames=John'
, they will still receive all names instead of triggering an error handling response as a bad request. How can this situation be addressed?