HTTP GET 200 vs 204

zdlgrj picture zdlgrj · Mar 4, 2016 · Viewed 8.6k times · Source

We are designing a public API, and trying to figure out what is the best practice for GET with following cases:

Path param:

/orders/{orderId}

Found: 200 with a response body.
Not Found: 404.

Query param:

/Products/{productId}/orders?color={color}

Found orders: 200 with response body.

Not found: Should this be a 200 or 204 or even a 404 in this case?

In my opinion, it should be 200 or 204 as the resource is found in this case and the query parameter is only performing the filter effect. But should we return a 200 or 204 in this case?

Answer

Paul Draper picture Paul Draper · Apr 19, 2021

Assuming that

(1) The first URL is for exactly one order.

(2) The second URL is for a list of 0 or more orders.


Missing an order in the first response should be a 404, since a not-an-order is not an order.

Missing orders in the second response should be a 200, since an empty list is still a list.