简体   繁体   中英

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, eg

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM