支持延迟加载所有属性的 Web 服务模式

发布于 2024-12-19 18:33:42 字数 1678 浏览 0 评论 0原文

我正在尝试为 Web 服务设计端点模板。我的主要要求是调用者能够指定应在返回的结果集中填充哪些属性。

我的服务返回部分对象的大型列表(最多 1M 条记录)以及单个完整对象,例如(粗略的示例 XML,抱歉有点冗长)

列表:

<items>
  <item>
    <a>aaa</a>
    <b>bbb</b>
  </item>
  <item>
    <a>aaaA</a>
    <b>bbbB</b>
  </item>
</items>

详细信息:

<item>
  <a>aaa</a>
  <b>bbb</b>
  <c>ccc</c>
  ...
  <w>
    <x>xxx</x>
    <y>yyy</y>
  </w>
  <z>zzz</z>
</item>

我考虑了以下想法:

  1. 返回完整的详细信息项目列表
  2. 创建一个更短的“列表”项类型,
  3. 传递调用者想要返回的属性名称的字符串数组

我倾向于第三个选项,但我想要一些不同的东西,它不支持子对象,我有考虑通过您希望返回的 xml 架构而不是数组。

我希望 API 支持延迟加载,这就是为什么第三种方法似乎也是可行的。

下面是 3. 的函数的示例:

public User GetUser(long ID, string[] properties)

然后调用者可以直接执行:

User.Email = GetUser(User.ID, "Email").Email

通过广泛使用默认值并隐藏 null,返回的 XML 将是:

<User>
  <ID>123</ID>
  <Email>[email protected]</Email>
</User>

现在,上面提到的问题正在尝试使它与上面的 之类的东西配合得很好,它本身具有子项,并且列表也可能具有子项。

由于我有太多的属性,我不能为每个属性只有一个 ws 方法。

我正在考虑选项 3。但是使用 xml 模式而不是 string[]..但我想不出一种简单的方法来定义它,我也不想使用 String属性的名称,例如“电子邮件”

最终计划是拥有一系列常用的预定义模式,只有在高级情况下,我们才需要实际定义所请求的属性。但我不知道所有将与我的 API 通信的系统,更不用说它们各自想要什么属性了(我们为每个调用者定制 API 是不可行的)。

还是我把一切都搞得太复杂了?

I am trying to design an endpoint template for a web service. My main requirement is that the caller is able to specify which properties should be populated in the returned result set.

My service returns large lists (up to 1M records) of partial objects as well as individual full objects such as (rough example XML, sorry it's a little verbose)

List:

<items>
  <item>
    <a>aaa</a>
    <b>bbb</b>
  </item>
  <item>
    <a>aaaA</a>
    <b>bbbB</b>
  </item>
</items>

Detail:

<item>
  <a>aaa</a>
  <b>bbb</b>
  <c>ccc</c>
  ...
  <w>
    <x>xxx</x>
    <y>yyy</y>
  </w>
  <z>zzz</z>
</item>

I have considered the following ideas:

  1. Returning the full detail items in the list
  2. Creating a 'list' item type that is shorter
  3. passing a string array of property names that the caller wants to be returned

I am leaning towards the 3rd option but I want something different to that it doesn't support sub objects, I have considered passing the xml schema that you want returned instead of an array.

I would like the API to support lazy loading which is why the 3rd way seems viable as well.

Here's an example of what a function for 3. would look like:

public User GetUser(long ID, string[] properties)

And then the caller could just go:

User.Email = GetUser(User.ID, "Email").Email

Through extensive use of default values and hiding nulls, the returned XML for that would be:

<User>
  <ID>123</ID>
  <Email>[email protected]</Email>
</User>

Now the problem as mentioned above is trying to make it play nice with things like <w> far above, which itself has sub items as well as the possibility for lists to have sub items.

As I have far too many properties, I cannot have just a ws method for each property.

I am considering option 3. but using an xml schema instead of a string[].. But I can't think of an easy way to define this, I would also like to not have to use String names for properties such as "Email".

The final plan is to have a series of pre-defined schemas that are used commonly and only in advanced cases would we need to actually define the requested properties. But I have no idea of all the systems that will be talking to my API, let alone what properties they might each want (it's not going to be feasible for us to tailor the API for every caller).

Or am I over complicating everything too much?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

风铃鹿 2024-12-26 18:33:42

我找到了有关部分响应和部分更新的 Google API 文档:

http://googlecode.blogspot.com/2011/07/lightning-fast-performance-tips-for.html

这似乎回答了我的问题。

I found the documentation for the Google APIs on Partial Responses and Partial Updates:

http://googlecode.blogspot.com/2011/07/lightning-fast-performance-tips-for.html

This seems to answer my question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文