gpt4 book ai didi

rest - 如何在 C# 中构建部分项目 RESTful API?

转载 作者:行者123 更新时间:2023-12-02 21:51:56 27 4
gpt4 key购买 nike

看来大多数 WebAPI 示例都返回一些模型(域模型或特定 View 模型)。

当使用域模型时,我们实际上通过 ajax 调用请求比 View 中所需的更多数据,然后使用 JavaScript 构建我们的 View 模型(假设我们正在构建一个 Web 应用程序)。

我尝试为每个页面( View )使用不同的 View 模型,这使我能够减少网络占用并仅返回需要的字段。但在 ApiController 中我会有太多 GET 方法。我们不可能预测 future 的需求并构建返回各种 View 模型的 API。

我想模仿 Facebook Graph API 并构建一个像这样的 uri:

http://... api/games/333?fields=id, name, price, imageUrl

我们的用户应该能够仅使用这几个字段更新记录。

详细说明可以在 Google Code 博客条目中找到:Making APIs Faster: Introducing Partial Response and Partial Update .

Some other posts here表明这超出了 ASP.NET WebAPI 当前的能力。 ServiceStack 或其他一些包会帮助我们实现目标吗?

最佳答案

尝试这个项目:https://github.com/AnthonyCarl/ServiceStack.PartialResponse对于问题的部分回答

ServiceStack.PartialResponse.ServiceModel

Google Style Partial Responses for ServiceStack.Net. Currently only the following Content types are supported:

  • application/json
  • application/jsv
  • text/html
  • application/xml is NOT currently supported.

I wanted to implement this as a ServiceStack IPlugin, but I was unable to figure out how to get the access I needed to the response DTO for my approach. Currently, this is implemented as an IRequestContext extension.

Providing Field Selectors

Field Selectors can be passed using the header or query string. By default field selectors are combined form both. Duplicate field selectors are reduced. The field selector is applied to all entries in a list if the selector refers to a list.

关于rest - 如何在 C# 中构建部分项目 RESTful API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18450329/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com