使用 OpenRasta 轻松地将项目添加到资源
我正在使用 OpenRasta 创建一个调查应用程序。
我有一个 SurveyResource,可在 /surveys/{id} 访问并可在 /surveys/{id}/edit 编辑
我现在想向调查添加问题,因为这是调查的重点,但我不确定执行此操作最轻松的方法是什么以及如何在 OR 中进行设置。
我想我应该有一个 QuestionResource (其中包含问题类型、问题文本等详细信息),并且应该将其发布到 /surveys/{id}/questions 并由问题处理程序处理,但我无法工作说明如何配置 OR。
我已将我的项目推送到 github https://github.com/oharab/OpenSurvey/tree/ add_question_to_survey
有人可以帮助我吗?
本
I'm using OpenRasta to create a Survey application.
I have a SurveyResource that is accessible at /surveys/{id} and editable at /surveys/{id}/edit
I'd now like to add questions to the survey, as that is the point of a survey, but I'm not sure what the most restful way of doing this is and how to set it up in OR.
I'm thinking I should have a QuestionResource (that has details of the question type, question text, etc) and it should be posted to /surveys/{id}/questions and handled by a question handler, but I can't work out how to configure OR.
I've pushed my project onto github at https://github.com/oharab/OpenSurvey/tree/add_question_to_survey
Can anyone help me?
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您想要对资源进行建模的方式。您完全有可能永远不会明确提供对单个问题的访问权限,并且会修改整个调查文档,如下所示:
如果您采用此路线,您甚至可以使用 HTML 或 HTML 5 作为您的内容,以便轻松使用由客户。现在您只需立即修改整个调查文档。
或者,您可能想单独解决每个问题,给它们一个单独的 URI,我认为这就是您所讨论的内容,如下所示:
这两个都不比另一个更 RESTful,区别仅在于调用的粒度。如果您需要后者的粒度,请为每个资源配置一个单独的处理程序,如下所示
it depends on the way you want to model your resources. It's perfectly possible that you'd never explicitly provide access to a single question, and would modify the entire survey document, like so:
If you go this route, you could even use HTML, or HTML 5 for your content so it's easy to consume by clients. Now you're just modifying the entire survey document at once.
Alternatively, you might want to separately address each question, giving them an individual URI, which I think is what you're talking about, like so:
Neither of these is more RESTful than the other, the difference is only in granularity of call. If you need the granularity of the latter, then configure yourself a separate handler per resource as in