keppla
keppla

Reputation: 1751

What is the correct http status code when URI parameter is wrong

Given i have a HTTP-Interface, and for example

POST /user

expects some specific JSON to be posted (for example {"username": "keppla"}), or

GET /search

expects a parameter like /search?term=whatisearch

When the client does not send the expected data, what would be a correct error code?

Upvotes: 0

Views: 2044

Answers (2)

Darrel Miller
Darrel Miller

Reputation: 142094

422 is a possibility, but it is not commonly used, as it is not widely known that it is permissible to use WEBDAV status codes even when you are not doing WEBDAV.

422 - The request was well-formed but was unable to be followed due to semantic errors

For the second scenario, you could argue that a 404 is more appropriate as it is the URI that is not correctly formed, rather than the request body.

Upvotes: 4

isobar
isobar

Reputation: 1175

400-499 is range for incomplete client requests. Looks like 400 is the right error code for your use case.

400 - Bad Request, The server could not understand the request, probably due to a syntax error.

Upvotes: 6

Related Questions