Search code examples
resthttphttp-status-codes

Response status code for searches in REST APIs


Suppose, we have the following API:

GET /api/guests/{id}
GET /api/guests?name=dummy

Which status code should I return when there are no guests matching criteria? I mean no guests with name dummy.

Should it be 404, 204 or 200 with an empty array?


Solution

  • I would return 200 with an empty array...
    Or a 204 (No Content)

    A 404 is when a resource isn't found. Your resource in this case is the collection of guests... which exists.