Monstieur
Monstieur

Reputation: 8112

404 depending on query string Parameters or strictly if route exists

Say I had a route such as /Item/Create/ which creates a new Item but requires a mandatory parameter called GroupId. It would have to be called via /Item/Create?GroupId=xxx. If the given GroupId doesn't exist can I return a 404 or is it wrong to return a 404 based on query string paramters?

I know it would be alright to return a 404 if my route itself was /Item/Create/{GroupId} and the GroupId was not found.

Upvotes: 0

Views: 265

Answers (1)

ThatBlairGuy
ThatBlairGuy

Reputation: 2462

It's not "wrong" per se, status 404 means "Resource not found" and you can't find a resource that hasn't been specified. Status 400 (Bad Request) however might be more appropriate. It really comes down to the intended meaning of the error code and your interpretation of the error.

A full list of status codes can be found in section 10 of RFC 2616. The 4xx (error) codes start in section 10.4.

Upvotes: 1

Related Questions