rawData
rawData

Reputation: 799

API rest response code for not handle endpoint

I have

/rest/drink/categories?alcohol=true

which is return 200 status code with list of drink categories that have alcohol in it, e.g.

200 ['wine','beer']

I wonder what status code should I use, if a user hit a none handled path like below

/rest/drink

or

/rest/drink?alcohol=true

Upvotes: 0

Views: 111

Answers (2)

Vinay Veluri
Vinay Veluri

Reputation: 6865

Http has status for such conditions.

4XX defines the error is from client side and needs a change.

Wiki says

The 4xx class of status code is intended for situations in which the client seems to have erred. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. These status codes are applicable to any request method. User agents should display any included entity to the user.[31]

For the condition where it is mentioned, its ideal to use 404 - Not Found or 400 - Bad Request

This gives list of all the status codes and appropriate explanation.

W3Org defined the specifications for these.

Upvotes: 2

rorschach
rorschach

Reputation: 2947

404 - Not found if the URL does not exist,
400 - Bad request if the URL exists but the request parameter is invalid.

Upvotes: 3

Related Questions