简体   繁体   English

在REST API中创建PUT和POST端点,而不创建GET端点?

[英]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. 考虑到我们已经有相同资源的POSTPUT端点,我不知道是否创建这样的端点不是一个坏主意。

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.

相关问题 如何在不指定内容类型的情况下将 JSON POST/PUT 到 REST API 端点:application/json header - How do I POST/PUT JSON to a REST API endpoint without specifying Content-Type: application/json header 在Java上创建Rest API-反向端点 - Create rest api on java - reverse endpoints 如何使用弹簧启动执行器分别捕获给定REST端点的GET,POST和PUT方法的度量 - How to capture metrics Separately for GET,POST and PUT method for given REST Endpoint using spring boot actuators 只有 Post REST api 有效,PUT、GET、DELETE api 在 spring 启动应用程序中不起作用 - Only Post REST api is working , PUT,GET,DELETE api's are not working in spring boot application 如何使用REST方法和REST方法获取REST API终结点的访问令牌,当前出现404错误? - How to get the access token of REST API endpoint using Rest Assured with POST method, Currently I am getting 404 error? 如何创建 REST API 然后 REST API 会将对象/字符串放入 ActiveMQ - how to create an REST API then the REST API will put object/string to ActiveMQ 如何创建具有多个端点连接到的单个端点 - How to creating a single endpoint with multiple endpoints connecting to it 如何在线调用 Rest Api 端点?如何将我的代码放入真实服务器 - How to call Rest Api endpoints online?How to put my code into real server springboot 中 REST api 的多个端点 - Multiple endpoints for REST api in springboot REST 如何在没有完整实体的情况下发布或放置(@RequestBody) - REST how to POST or PUT without full entity(@RequestBody)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM