should API return 404 status for api/object?filter=param?

207 Views Asked by At

Which HTTP status must be returned for api/object?filter=param if record not found? I see following variants:

  • return 404
  • return 200 and blank response, for example {}

I don not find conventions for ruby community. What is best practice?

1

There are 1 best solutions below

0
Patrick Barattin On

You can go in the deep here: Proper REST response for empty table?

I think is correct to replay 200 with an empty object if you are calling an 'index' endpoint with search params

  • request: users?age=18
  • response: code 200, body{}

But if you are calling a 'show' endpoint you should return 404

  • request: users/1
  • response: code 404