如何区分实体不存在和不正确的端点之间的 404? [英] How to distinguish 404 between entity doesn't exist and incorrect endpoint?

查看:38
本文介绍了如何区分实体不存在和不正确的端点之间的 404?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 REST 原则,404 似乎用于指示实体不存在.但是,客户端如何将这种情况与完全命中不正确的端点区分开来?

Using REST principles, 404 seems to be used to indicate that an entity does not exist. However, how can clients distinguish this case from hitting an incorrect endpoint altogether?

我想区分您到达了正确的端点,但该实体不存在"和您未到达正确的端点".从技术上讲,这可以使用其他响应代码、自定义标头等加以区分.但我主要关注这方面的 REST 最佳实践,以便客户端尽可能简单和标准.

I want to distinguish between, "you came to the right endpoint, but that entity doesn't exist" and "you're not at the right endpoint". Technically, this can be distinguished using other response codes, custom headers, etc. but I am mainly concerned with REST best-practices in this area so clients are as simple and standard as possible.

推荐答案

你来到了正确的终点,但是该实体不存在

you came to the right endpoint, but that entity doesn't exist

如果 URL 没有识别资源,它怎么可能是正确的端点?我能想到的唯一可能的情况是实体已被删除,在这种情况下 410 Gone 是正确的响应.

If there is no resource identified by the URL, how could it be the right endpoint? The only possible scenario I could think of is that the entity has been deleted, in which case 410 Gone is the correct response.

请记住,如果您遵循 RESTful 原则,那么 URL 应该由服务器提供,如果是,为什么服务器会分发无效的 URL?

Remember that if you are following RESTful principles then the URL should have been provided by the server and if so, why is the server handing out invalid URLs?

这篇关于如何区分实体不存在和不正确的端点之间的 404?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆