说明:随微软ASP.NET MVC 4一起发布的还有一个框架,叫做ASP.NET Web API。目前国内关注这项技术的人似乎还很少,这方面的文章也不多见。开发Web应用程序也许可以只用MVC这样的技术,而不用这项Web API技术,但如果用了,会给你的应用程序带来极大的好处。为此,本人转载并翻译了以下这篇文章,后面还会陆续翻译该项技术的一些官方教程。大家一起学习,共同提高。
Microsoft ASP.NET: What‘s This New Web API?微软ASP.NET:新的Web API是什么?
摘自:
Don Kiely explains why Microsoft‘s Web API shines as a new technology for developers
Don Kiely解释为什么微软的Web API是开发人员的一项耀眼的新技术。
Don Kiely
Dev Pro
InstantDoc ID #142516
March 08, 2012 08:00 AM
After a respite in 2011 from new product mania, Microsoft is on a tear in 2012 to release early versions for many of its development tools. In the past couple of weeks we‘ve seen a preview for Visual Studio 2011 and ASP.NET MVC 4. We also got our first look at the SQL Server 2012 release candidate. These new releases mark an exciting time for technology, even if it means reevaluating these technologies and determining what skills developers should learn and focus on.
经过2011新产品*的一段喘息之后,微软2012年猛然发布了许多开发工具的早期版本。在前几个星期我们看到了Visual Studio 2011和ASP.NET MVC 4的预览版。我们也拿到了SQL Server 2012预发行版。这些最新发布标志着技术令人激动的时刻,尽管这仅意味着对这些技术的重新评估,并决定着开发人员应当学习和关注哪些技能。
One truly new and exciting technology for Microsoft is the Web API. I wasn‘t initially enthusiastic about this API, because it seemed to be another web service that‘s similar to the RESTful API. Do we really need another API when we already have ASP.NET Web Services and Windows Communication Foundation (WCF), or has Microsoft gone nutty about these kinds of APIs just as it has with data-access APIs?
一项真正全新且令人兴奋的微软技术是Web API。我最初并不热衷于这个API,因为它似乎只是类似于REST化API的另一项web服务。在已经有了ASP.NET Web Services(ASP.NET Web服务)和Windows Communication Foundation(Windows通信基础 — WCF)时,还真正需要另外一种API吗?或者,微软已经陷入疯狂制作各种API,就像它做数据访问API那样?
I won‘t address the last part of that question—Microsoft seems pretty nutty at times—but I‘m really starting to warm up to the new Web API, particularly because it‘s solidified into what appears to be the actual release API. I‘ve come to realize that the reason for this is that the Web API feels natural and seems to fit in with the kinds of applications that I build. The Web API is far more than the relatively basic and hard-to-secure ASP.NET Web Services and the mind-numbingly complex WCF that always feels like a gross overkill for most things a website needs to do. At least this situation is true for the kinds of applications that I build most often these days.
我没有注意到问题的后一部分 — 微软有时确实是相当疯狂的 — 但我对这个新的Web API真正开始热衷起来了。我开始认识到,这么做的原因是Web API感觉自然,而且它似乎适合于我所建立的各种应用程序。Web API远远超过了相对基本且难以安全的ASP.NET Web服务,而极为复杂的WCF总让人感觉对于web网站要做的事件就像杀鸡用了牛刀。至少,对于我这些日子最经常建立的各种应用程序而言,情况确实是这样。
I‘ve outlined some pretty subjective reasons for why I like the new Web API. From an objective and raw technology perspective, the Web API is designed and lives for HTTP. One complex problem with WCF is that it provides everything for everyone for every transport protocol, as Matt Milner explains in his blog post. You have to do some work to use WCF over HTTP. In contrast, the Web API is designed from the ground up to make good use of HTTP, warts and all. The Web API isn‘t exactly lightweight, but with only one protocol to support the API, it doesn‘t have a lot of excess baggage.
我概括了为什么喜欢这个新的Web API的一些相当主观的原因。从客观和原始技术的观点看,Web API是为HTTP而设计和存在的。WCF的一个复杂问题是它对每一个传输协议提供了方方面面的东西,就像Matt Milner在他的博客文章所解释的那样。你必须做一些工作才能将WCF运用于HTTP。与之相反,Web API毫无保留地就是围绕充分利用HTTP而设计的。Web API其实并不是轻量级的,但它只针对一个协议来支持API,它不会产生很多超重的包袱。
The other thing that I like about the Web API is that it reflects the direction in which the web is headed. As Scott Guthrie points out in the first part of his blog post series about the Web API, many large websites are exposing Web APIs to make their services available to third-party applications (he cites Facebook, Twitter, LinkedIn, and Netflix as examples). He also lists a bunch of reasons why a Web API is a good solution, including a modern HTTP programming model. It‘s about time Microsoft got around to providing this model!
我喜欢Web API的另一件事是,它反映了web前进的方向。正如Scott Guthrie在他关于Web API系列文章的第一部分(中文版网址:)所指出的那样,许多大型网站都暴露了Web API,以使第三方应用程序能运用它们的服务(他例证了Facebook、Twitter、LinkedIn,以及Netflix等)。他也列出了一打理由,以说明为什么Web API是一种好的解决方案,包括一个“现代HTTP编程模型”。现在,已经到了微软提供这种模型的时候了!