[英]Create PUT and POST endpoints in a REST API, without creating a GET endpoint?
I am writing the endpoints for a resource items
, that is a subresource of applications
, like this: applications/{:id}/items
. 我正在为资源
items
(这是applications
的子资源)编写端点,例如: applications/{:id}/items
。 Both, items and applications have other properties apart from their name. 项目和应用程序除名称外均具有其他属性。
I have created 我创造了
GET applications/{:applicationId}/items
- returns the list of items that belong to an application GET applications/{:applicationId}/items
返回属于应用程序的项目列表
POST applications/{:applicationId}/items
- creates an item for an application POST applications/{:applicationId}/items
为应用程序创建一个项目
PUT applications/{:applicationId}/items/{:itemNumber}
- updates an item of an application PUT applications/{:applicationId}/items/{:itemNumber}
-更新应用程序的项目
The clients are generally only interested to see a list of items for an application and not individual items, so my team thinks that creating the endpoint 客户通常只希望查看应用程序的项目列表,而不是单个项目,因此我的团队认为创建端点
GET applications/{:applicationId}/items/{:itemNumber}
is unnecessary. 是不必要的。 I am wondering if it is a bad idea not to create such an endpoint considering that we already have
POST
and PUT
endpoints for the same resource. 考虑到我们已经有相同资源的
POST
和PUT
端点,我不知道是否创建这样的端点不是一个坏主意。
It is perfectly acceptable to create a PUT without a matching GET. 创建没有匹配的GET的PUT是完全可以接受的。
If you find that you need it at a later date you can add it; 如果以后发现需要,可以添加它; if however you create it before you need it, you will be carrying code which is neither needed nor used, but you will still have to maintain and test it.
但是,如果在需要之前创建了它,则将携带既不需要也不使用的代码,但是您仍然必须维护和测试它。
If you don't want to test or maintain it, then you should delete it. 如果您不想测试或维护它,则应将其删除。
THERE ARE NO BUGS IN DELETED CODE 删除的代码中没有错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.