[英]While forming a REST URL for our application, how should we differentiate two services related to the same object?
need two services related to the object "item". 需要与对象“ item”相关的两个服务。
To get the details of the item. 获取项目的详细信息。 Though it is a method to get data, I will be using POST since my pathParam/MatrixParam list is too long(Say, purchaserIds provided in the matrixParam is used to fetch the items they have bought).
尽管这是一种获取数据的方法,但由于pathParam / MatrixParam列表太长(我会使用MatrixParam中提供的purchaseIds来获取他们购买的商品),所以我将使用POST。 To avoid "URI too long" exception, I made it POST.
为了避免出现“ URI太长”异常,我将其设为POST。
To save the item with some details. 保存带有一些细节的项目。 This will also be a POST method since it is saving/updating.
这也将是POST方法,因为它正在保存/更新。
Now, both services will have the same url http://...../item and both will have httpMethod as POST. 现在,这两个服务将具有相同的URL http://...../item,并且都将具有httpMethod作为POST。
How can we differentiate these 2 services by the URL? 我们如何通过URL区分这两种服务? Is it right to make it " http://.../item/save " and ".../item/get"?
将其设置为“ http://.../item/save ”和“ ... / item / get”是否正确?
If your URLs would end up too long, it sounds like your URL design is wrong - GET against http://.../items/1/purchasers/
would (for example) be a decent URL to return all the people who have bought item 1, then to update item 1, you would PUT to http://.../items/1/
and to create an item you would POST to http://.../items/
如果您的网址结尾太长,听起来您的网址设计有误-例如,针对
http://.../items/1/purchasers/
GET http://.../items/1/purchasers/
将是一个不错的网址,以返回所有拥有该网址的用户购买了第1件,然后更新第1件,则将其http://.../items/1/
到http://.../items/1/
并创建一个商品,然后将其发布到http://.../items/
The URL scheme you decide does not sound RESTful, as you're using it to describe actions rather than resources - the URL should identify the resource you are accessing rather than what to do to it. 您确定的URL方案听起来不是RESTful的,因为您正在使用它来描述操作而不是资源-URL应该标识您正在访问的资源,而不是要做什么。
To get the details of item you will need to use GET method with item id as path parameter. 要获取商品的详细信息,您将需要使用带有商品ID作为路径参数的GET方法。
http://....../itemid HTTP://....../itemid
using POST for GET will defeat the purpose and entire design of the api will be disturbed. 使用POST进行GET将无法达到目的,并且会干扰api的整个设计。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.