If data is not available - what should I return as a status code?

Viewed 20

I am building a API with banking operations.

I have 2 dict for my data:

accounts_data = {}
accounts_transaction_data = {}

I have this scenario

accounts_data = {"Jack": 0}

accounts_transaction_data = {}

When I search for Jack's transaction history:

  • First I check to make sure there is an account for Jack

    True

  • After that I am looking in accounts_transaction_data for data ti return. But there is no data, because of Jack did not make any money transactions yet.

Here is my question:

Should I return a HTTP 404 status code? With a message like:

There is no transaction history for the account name you entered to see the transaction history

OR

Should I return a HTTP 200 status code? With a message like:

There is no transaction history for the account name you entered to see the transaction history

200 or 404 ?

Thanks for your help!

1 Answers

In my opinion 200 is more appropriate, as the endpoint is existing. It is just not holding any data. In addition, the empty list should be returned, so the caller can filter and check for himself, if there are values. This way the endpoint behaves the same way all the time.

Related