使用 OpenRasta 轻松地将项目添加到资源

发布于 2024-11-29 12:09:24 字数 503 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千寻… 2024-12-06 12:09:24

这取决于您想要对资源进行建模的方式。您完全有可能永远不会明确提供对单个问题的访问权限,并且会修改整个调查文档,如下所示:

PUT /surveys/123

<survey>

  <link rel="update" href="/surveys/123" method="PUT"
        type="application/vnd.mycorp.survey+xml" />

  <question id="age">
    <label>How old are you?</label>
    <select>
      <option>0 - 5</option>
      <option>6 - 10</option>
      <option>10 - 13</option>
    </select>
  </question>
</survey>

如果您采用此路线,您甚至可以使用 HTML 或 HTML 5 作为您的内容,以便轻松使用由客户。现在您只需立即修改整个调查文档。

或者,您可能想单独解决每个问题,给它们一个单独的 URI,我认为这就是您所讨论的内容,如下所示:

GET /survey/123

<survey>
  <link rel="add-question" href="/survey/123/questions"      
        type="application/vnd.mycorp.surveyquestion+xml" method="POST" />

  <question>

    <link rel="delete" href="/questions/123-age" method="DELETE" />
    <link rel="update" href="/questions/123-age" type="application/vnd.mycorp.surveyquestion+xml" method="PUT" />

    <label>How old are you?</label>
    <select>
      <option>0 - 5</option>
      <option>6 - 10</option>
      <option>10 - 13</option>
    </select>
  </question>
</survey>

这两个都不比另一个更 RESTful,区别仅在于调用的粒度。如果您需要后者的粒度,请为每个资源配置一个单独的处理程序,如下所示

using(OpenRastaConfiguration.Manual)
{
   ResourceSpace.Has.ResourcesOfType<Survey>().AtUri("/survey/{id}").HandledBy<SurveyHandler>();
   ResourceSpace.Has.ResourcesOfType<Question>().AtUri("/questions/{id}").HandleBy<QuestionHandler>();
}

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:

PUT /surveys/123

<survey>

  <link rel="update" href="/surveys/123" method="PUT"
        type="application/vnd.mycorp.survey+xml" />

  <question id="age">
    <label>How old are you?</label>
    <select>
      <option>0 - 5</option>
      <option>6 - 10</option>
      <option>10 - 13</option>
    </select>
  </question>
</survey>

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:

GET /survey/123

<survey>
  <link rel="add-question" href="/survey/123/questions"      
        type="application/vnd.mycorp.surveyquestion+xml" method="POST" />

  <question>

    <link rel="delete" href="/questions/123-age" method="DELETE" />
    <link rel="update" href="/questions/123-age" type="application/vnd.mycorp.surveyquestion+xml" method="PUT" />

    <label>How old are you?</label>
    <select>
      <option>0 - 5</option>
      <option>6 - 10</option>
      <option>10 - 13</option>
    </select>
  </question>
</survey>

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

using(OpenRastaConfiguration.Manual)
{
   ResourceSpace.Has.ResourcesOfType<Survey>().AtUri("/survey/{id}").HandledBy<SurveyHandler>();
   ResourceSpace.Has.ResourcesOfType<Question>().AtUri("/questions/{id}").HandleBy<QuestionHandler>();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文