简体   繁体   中英

Return http-status-code 200 or 204 if no content found to process

In web-API client made a get request with a parameter, to process something and get data from the file system. The parameter requested through the API a folder path. If API found that path, it is processing something on the resources inside and returning the processed content with Http-200 status code. This is perfect.

What if the folder exists and while processing some content missing in the path to process. Should API return Http-200 with empty content or Http-204 with/without response message?

It depends on how you view the situation and how you interpret the result:

  • 200 - The request successfully executed
  • 204 - The request executed successfully but didn't produce anything to return
  • 400 - The request was not successful as the resource doesn't exist

you could use any of the above if you feel it is correct to do so, if a user tries to find an account via a GetAccount function that accepts an account number as input and that account doesn't exist I would return a 400 bad request error as the account did not exist, but I would also return an error string with something like 'unrecognised account number'

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