我是API设计和MVC概念的新手,但据我所知,像GET/api/products这样的东西应该返回一个产品列表,而GET/api/products/1应该返回一个产品.在速度方面,我的感觉是/ api/products应该返回较少的信息,即id和name,而/ api/products/1应该返回更多,即id,name和description.
据我所知,处理此问题的最佳方法是不在/ api/products端点中返回产品类的某些字段.对于/ api/products?fields = name,这尤其必要.我正在使用ASP.Net Web Api 2并尝试了以下方法:
有什么简单的方法可以做我想做的事情吗?
否则你能建议一个比我正在做的更好的API设计吗?
我阅读http://www.asp.net/web-api/overview/security/working-with-ssl-in-web-api并尝试使用该页面中的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Http.Filters;
using System.Web.Http.Controllers;
public class RequireHttpsAttribute : AuthorizationFilterAttribute
{
public override void OnAuthorization(HttpActionContext actionContext)
{
if (actionContext.Request.RequestUri.Scheme != Uri.UriSchemeHttps)
{
actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden)
{
ReasonPhrase = "HTTPS Required"
};
}
else
{
base.OnAuthorization(actionContext);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我构建时,我没有收到错误,但运行时给出了这个错误:
CS0012:类型'System.Net.Http.HttpRequestMessage'在未引用的程序集中定义.您必须添加对程序集'System.Net.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'的引用.
我的项目的参考文件夹中有一个对System.Net.Http的引用.如果我查看它的属性,它会说版本4.0.0.0和运行版本4.0.30319.我的项目属性说目标框架是.NET 4.5.
我在VS2013 Express中的IntelliSense也不想接受与HttpResponseMessage或HttpRequestMessage有关的任何事情.
我已经尝试删除引用并重新添加它,但无济于事.
任何帮助将非常感激.
我一直在阅读关于离线(本地)存储和AngularFire的SO,我知道AngularFire用于与Angular模型和DOM的3路绑定使用.
具体参考如何在设备联机时将脱机数据库与Firebase同步?我可以看到,将本地存储引入混合中并不是一件小事.我不太明白在该线程中"启动"Firebase的概念.
但是,我确实需要能够在离线模式下启动应用程序.这是我的情景:
我知道Kato还提到在AngularFire的未来版本中可能会有离线存储功能 - 这是否还有可能?否则我的想法是这样做:
它不是一种好方法,但我不知道其他任何方式.有没有办法直接将Firebase绑定到本地存储?