RESTful 问题/答案设计?
这是我目前正在进行的一个玩具项目。
我的应用程序包含带有多项选择答案的问题。
问题url的格式如下,带有GET
& POST
映射到问题控制器上的不同操作。
GET: url.com/questions/:category/:difficulty => 'ask'
POST: url.com/questions/:category/:difficulty => 'answer'
我想知道是否值得将其重新设计为 RESTful 风格。我知道我需要引入答案作为资源,但我正在努力想出一个看起来很自然的网址来回答这个问题。
重新设计值得吗?您将如何构建 url?
This is a toy project I'm working on at the moment.
My app contains questions with multiple choice answers.
The question url is in the following format, with GET
& POST
mapping to different actions on the questions controller.
GET: url.com/questions/:category/:difficulty => 'ask'
POST: url.com/questions/:category/:difficulty => 'answer'
I'm wondering if it's worth redesigning this into a RESTful style. I know I'd need to introduce answers as a resource, but I'm struggling to think of a url that would look natural for answering that question.
Would a redesign be worthwhile? How would you go about structuring the urls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为如果你映射:
如果你这样做:
那么你只能有一个具有指定类别和难度的问题。
I think it would be better if you map:
If you would do:
Then you could have only one question with specified category and difficulty.
您不一定需要将答案视为单独的资源:您可以将答案视为问题的元素。事实上,我认为这样会更好——除非与问题相关,否则答案实际上没有任何价值。
You don't necessarily need to treat answers as a separate resource: you could treat an answer as an element of a question. In fact, I think this would be better - an answer isn't really worth anything unless it's tied to a question.