2

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.

0

1 Answer 1

1

Whether you identity a resource using a path parameter or a query parameter, you're identifying a resource, so if it isn't found, you return 404 Not Found.

Examples

https://samples-service.com/rest/v1/qvc/{countryCode}/users
https://samples-service.com/rest/v1/qvc/users?countryCode={countryCode}

If the request has query parameters that have defined restrictions, e.g. pageSize must be between 1 and 100 inclusive, then a value outside that range is invalid, and you should return 400 Bad Request.

Examples

https://samples-service.com/rest/v1/qvc/US/users?pageSize=0
https://samples-service.com/rest/v1/qvc/users?countryCode=US&pageSize=0
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.