如果数据不可用 - 我应该作为状态代码返回什么?
我正在建立具有银行业务的API。
我的数据有2个dict:
accounts_data = {}
accounts_transaction_data = {}
我有这种情况
accounts_data = {"Jack": 0}
accounts_transaction_data = {}
当我搜索杰克的交易历史记录时,
- :
首先,我检查一下杰克
的帐户true
之后,我正在查找
accounde_transaction_data
for data ti返回。但是没有数据,因为杰克还没有赚钱交易。
这是我的问题:
我应该返回HTTP 404状态代码吗?带有类似的消息:
您输入的帐户名称没有交易历史记录,以查看交易历史记录
,还是
我应该返回HTTP 200状态代码?带有类似的消息:
您输入的帐户名称没有交易历史记录,以查看交易历史记录
200 或 404 ?
感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为200更合适,因为端点存在。它只是没有持有任何数据。此外,应返回空列表,以便呼叫者可以过滤并检查自己,如果有值。这样,端点一直以相同的方式行为。
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.