0

I am creating a REST API which will run a simple database query and return some data, based on the payload.

If my SQL query returns no results then I am returning the plain text "No Records Found".

What HTTP response code would be appropriate for such an event. Is it 200 or 404.

1 Answer 1

5

If you are returning a JSON payload and your resource can be represented as a collection, then it makes sense to return 200 along with an empty array ([]) in the response payload.

If you are returning a single resource for a given identifier, and no resource can be found with the given identifier, then it makes sense to return 404.

Sign up to request clarification or add additional context in comments.

1 Comment

This is the correct answer. Getting an empty collection is like receiving an empty package. The package exists (so no 404), but there's nothing in it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.