在RESTful架构中发布的正确方法 [英] Proper way to post in a RESTful architecture

查看:115
本文介绍了在RESTful架构中发布的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

REST体系结构中张贴本质上分层的内容的正确方法是什么?
让我解释一下.

假设我有一个问答应用程序.
用户发布问题,每个问题可以有很多答复.

提取ID为1的问题时,我会这样做:
获取:/question/1

在获取问题1的答案时,我会这样做:
获取:/question/1/回复
(这将返回响应列表)

如果我自己一个人得到回应,我会这样做:
获取:/response/2

现在,我将如何发布对问题1的新答复?
我不确定哪种方法正确:

选项1:
POST:/question/1/response

选项2:
POST/响应

在选项1中,我尊重层次结构并在其中进行操作.我知道在URL中将响应添加到哪个问题(资源).

在选项2中,我需要在我的发布参数中包含问题ID.在这里,我基本上将忽略自然的层次结构,并将问题ID像响应中的其他任何属性一样对待.

我认为,正确的方法是选择2.响应是独立的资源.最后,问题ID只是响应的属性.

好吧...?

谢谢

What is the proper way in a REST architecture to post something that is hierarchical in nature?
Let me explain.

Let''s say I have a question and answer application.
Users posts questions, and each question can have many responses.

When fetching a question, with ID of 1, I would do:
GET: /question/1

When fetching the responses for question 1, I would do:
GET: /question/1/responses
(this would return a list of responses)

If I were to get a response, all by itself, I would do:
GET: /response/2

Now, How would I post a new response to question 1?
I am unsure of which approach would be correct:

Option 1:
POST: /question/1/response

Option 2:
POST /response

In Option 1, I respect the hierarchy, and operate in it. I know in the URL to which question (resource) the response will be added.

In Option 2, I need to include the Question ID in my post params. Here I would basically ignore the natural heirarchy, and treat the question ID like any other attribute on the response.

I think, the right way is option 2. Response is a stand-alone resource. In the end, Question ID is just an attribute of a response.

Well...?

Thanks

推荐答案

真的来了吗?
没有REST狂热者想为我滥用REST而撕毁我吗?
没有人有任何意见吗?

它的开放性让任何人都可以将我撕碎...
Come on...really?
No REST fanatic wants to rip me a new one for my misuse of REST?
nobody has any opinion at all?

its wide open for anybody to just tear me apart...


这篇关于在RESTful架构中发布的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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