I am a little confused about what should a service return for invalid path parameter and invalid query parameter. Especially for path parameters, nobody able confirm whether it is 400 or 404.
Let's say following is the service endpoint : https://samples-service.com/rest/v1/qvc/{countryCode}/users?numberOfusers=10
countryCode is the path parameter.
- Acceptable country codes are US and UK.
- If a user enters an incorrect country code, what should be the response? 400 Bad Request or 404 Not Found?
I have heard people provide justification for both of these responses.
Justification for 404: If the user tries to hit an invalid path then the service should return 404 Not Found. So since it is a path parameter, it should 404
Justification for 400 Since is the incorrect parameter. It should be 404. Doesn't matter whether it is a path parameter or query parameter or payload
For me, both of these make kind of sense. Not sure which is the correct one.
numberOfusers is the query parameter If a user enters an invalid number (eg: negative number, -9). What should the service return 400 or 404. I think in this case 400 is acceptable. But just want to confirm.