如果数据不可用 - 我应该作为状态代码返回什么?

发布于 2025-01-30 15:33:26 字数 704 浏览 3 评论 0原文

我正在建立具有银行业务的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

停顿的约定 2025-02-06 15:33:26

我认为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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文