2

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?

1 Answer 1

1

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'

5
  • 2
    "400 - The request was not successful as the resource doesn't exist" did you mean 404. 400 - Bad Request normally means there was something wrong with the request itself.
    – phuzi
    Commented Jul 5, 2019 at 7:55
  • its a difficult one, 404 would suggest the endpoint didn't exist but if the endpoint accepted the request and processed it and it didn't have a return because the user asked for something outside the scope then I'd return a 400. I think its a murky area, I personally feel 404 should be reserved for situations the requested URL doesn't exist but I think personal choice comes in a lot here and as long as its documented in your API doc then you have a fair bit of artistic licence
    – Mike
    Commented Jul 5, 2019 at 8:01
  • 2
    it's not a bad request 400, since the api receive valid parameters and it's even processing with that,
    – jidh
    Commented Jul 5, 2019 at 8:02
  • 1
    @mike, actually 400 and 404 are out of context here, since i have procee the request successful with input patams, but the result of the process is null / nothing. so i confused to choose 200 with empty array or 204 directly.
    – jidh
    Commented Jul 5, 2019 at 8:05
  • @Mike Check out this question/answer, it reflects the consensus on use of 400 vs 404.
    – phuzi
    Commented Jul 5, 2019 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.