资源和正交资源问题

资源和正交资源问题

本文介绍了RESTful 资源和正交资源问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在通过 HTTP 访问的中间层使用具有面向 RESTful 资源的服务的 3 层应用程序,那么向 UI 层提供正交资源的最佳方法是什么?

If I'm using a 3-tier app with a RESTful resource orientated service in the middle tier accessed via HTTP, what is the best way to provide orthogonal resources to the UI tier?

这样的一个例子是一个用户"资源,它有一个国家的字段/属性,现在在编辑用户时在 UI 层我希望能够从下拉菜单中选择,然后通过以下方式更新资源一个 PUT 操作.

An example of this would be a 'User' resource which has a field/property for a Country, now in the UI tier when editing the User I want to be able to pick from a drop down and then update the resource via a PUT operation.

问题是国家/地区列表如何进入用于编辑用户的用户界面?- 我是向服务发出 2 个单独的请求,一个针对国家/地区资源,一个针对用户资源,还是将它们合并为 1 个请求.

The question is how does the Country list get to the UI for editting the User? - do I make 2 seperate requests to the service, one for the Country resources and one for the User resource or do I combine these into 1 request.

推荐答案

做两个请求.这允许每个表示具有不同的缓存规则.缓存国家/地区列表可能是个好主意.

Do two requests. This allows each representation to have difference caching rules. Caching the country list is probably a good idea.

当我这样做时,我的 XML 表示如下:

When I do this, my XML representation looks like:

<User>
    <Name>Bob Brown</Name>
    <Country DomainUrl="/Setup/Country/PickList">
      <Code>US</Code>
      <Description>United States</Description>
    </Country>
</User>

我还推迟加载国家/地区列表,直到用户实际单击下拉列表.

I also defer the loading of the Country list until the user actually clicks on the drop down.

这篇关于RESTful 资源和正交资源问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 22:43