【翻译】ASP.NET Web API是什么?

简介: 原文 【翻译】ASP.NET Web API是什么? 说明:随微软ASP.NET MVC 4一起发布的还有一个框架,叫做ASP.NET Web API。目前国内关注这项技术的人似乎还很少,这方面的文章也不多见。

原文 【翻译】ASP.NET Web API是什么?

说明:随微软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是什么?

摘自:http://www.devproconnections.com/article/asp/microsoft-aspnet-web-api-142516

Don Kiely explains why Microsoft's Web API shines as a new technology for developers
Don Kiely解释为什么微软的Web API是开发人员的一项耀眼的新技术。

WhatsAPI
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系列文章的第一部分(中文版网址:http://blogs.msdn.com/b/scottgu/archive/2012/03/26/asp-net-web-api.aspx)所指出的那样,许多大型网站都暴露了Web API,以使第三方应用程序能运用它们的服务(他例证了Facebook、Twitter、LinkedIn,以及Netflix等)。他也列出了一打理由,以说明为什么Web API是一种好的解决方案,包括一个“现代HTTP编程模型”。现在,已经到了微软提供这种模型的时候了!

I love the close integration of the Web API with ASP.NET MVC. Microsoft chose to implement custom Web APIs by using the well-established controller model. This makes sense because a lot of people were already implementing custom Web APIs by using MVC controllers that return JSON data to the client. That's a slick solution, and the Web API just makes it better. The only big difference is that a Web API controller implements ApiController class instead of Controller class, which in turn implements the IHttpController interface. ApiController is a relatively simple class in the System.Web.Http namespace, so it isn't tied exclusively to ASP.NET MVC, but it understands the HTTP protocol and most of its common verbs.
我喜欢Web API与ASP.NET MVC的密切集成。微软通过运用建立良好的控制器模型来选择实现自定义Web API。这是有意义的,因为,通过使用MVC的控制器把JSON数据返回给客户端的办法,很多人都已经实现了自定义Web API。这是一个平滑的解决方案,而且Web API恰恰使之更好。唯一大的差别是Web API控制器实现的是ApiController类,而不是Controller类,它转而实现了IHttpController接口。ApiController是System.Web.Http命名空间中的一个相对简单的类,因此它并未专门绑定于ASP.NET MVC,但它能够理解HTTP协议及其大多数常规谓词。

Best of all, the API is available to a wide variety of clients, including mobile applications. In fact, this fact is probably its biggest selling point. Web applications are increasingly not limited to applications that run in a desktop browser.
最好原因是,这种API可用于十分广泛的客户端,包括移动应用程序。事实上,这一事实可能是它最大的卖点。Web应用程序已经日益不仅限于运行在桌面浏览器的应用程序了。

I'm not as big a fan of Microsoft's Web API as I am of Entity Framework, but I can already feel the tug. It'll be interesting to see how widely used this new technology becomes when it's finally released, but right now Web API is looking like a winner.
我是实体框架而不是微软Web API的大粉丝,但我已经能够感觉到这种拽力。看到新技术在它最终发布时变得广泛使用是很有趣的,而现在,Web API渐渐看起来像是一个赢家。

目录
相关文章
|
4天前
|
人工智能 搜索推荐 IDE
突破网页数据集获取难题:Web Unlocker API 助力 AI 训练与微调数据集全方位解决方案
本文介绍了Web Unlocker API、Web-Scraper和SERP API三大工具,助力解决AI训练与微调数据集获取难题。Web Unlocker API通过智能代理和CAPTCHA绕过技术,高效解锁高防护网站数据;Web-Scraper支持动态内容加载,精准抓取复杂网页信息;SERP API专注搜索引擎结果页数据抓取,适用于SEO分析与市场研究。这些工具大幅降低数据获取成本,提供合规保障,特别适合中小企业使用。粉丝专属体验入口提供2刀额度,助您轻松上手!
36 2
|
16天前
|
人工智能 运维 安全
网络安全公司推荐:F5荣膺IDC全球Web应用与API防护领导者
网络安全公司推荐:F5荣膺IDC全球Web应用与API防护领导者
39 3
|
4月前
|
开发框架 前端开发 JavaScript
ASP.NET Web Pages - 教程
ASP.NET Web Pages 是一种用于创建动态网页的开发模式,采用HTML、CSS、JavaScript 和服务器脚本。本教程聚焦于Web Pages,介绍如何使用Razor语法结合服务器端代码与前端技术,以及利用WebMatrix工具进行开发。适合初学者入门ASP.NET。
|
1月前
|
XML JSON API
Understanding RESTful API and Web Services: Key Differences and Use Cases
在现代软件开发中,RESTful API和Web服务均用于实现系统间通信,但各有特点。RESTful API遵循REST原则,主要使用HTTP/HTTPS协议,数据格式多为JSON或XML,适用于无状态通信;而Web服务包括SOAP和REST,常用于基于网络的API,采用标准化方法如WSDL或OpenAPI。理解两者区别有助于选择适合应用需求的解决方案,构建高效、可扩展的应用程序。
|
6月前
|
Java API 数据库
构建RESTful API已经成为现代Web开发的标准做法之一。Spring Boot框架因其简洁的配置、快速的启动特性及丰富的功能集而备受开发者青睐。
【10月更文挑战第11天】本文介绍如何使用Spring Boot构建在线图书管理系统的RESTful API。通过创建Spring Boot项目,定义`Book`实体类、`BookRepository`接口和`BookService`服务类,最后实现`BookController`控制器来处理HTTP请求,展示了从基础环境搭建到API测试的完整过程。
102 4
|
1月前
|
机器学习/深度学习 开发框架 API
Python 高级编程与实战:深入理解 Web 开发与 API 设计
在前几篇文章中,我们探讨了 Python 的基础语法、面向对象编程、函数式编程、元编程、性能优化、调试技巧以及数据科学和机器学习。本文将深入探讨 Python 在 Web 开发和 API 设计中的应用,并通过实战项目帮助你掌握这些技术。
|
4月前
|
运维 前端开发 C#
一套以用户体验出发的.NET8 Web开源框架
一套以用户体验出发的.NET8 Web开源框架
116 7
一套以用户体验出发的.NET8 Web开源框架
|
3月前
|
开发框架 数据可视化 .NET
.NET 中管理 Web API 文档的两种方式
.NET 中管理 Web API 文档的两种方式
73 14
|
5月前
|
开发框架 .NET 程序员
驾驭Autofac,ASP.NET WebApi实现依赖注入详细步骤总结
Autofac 是一个轻量级的依赖注入框架,专门为 .NET 应用程序量身定做,它就像是你代码中的 "魔法师",用它来管理对象的生命周期,让你的代码更加模块化、易于测试和维护
155 4
驾驭Autofac,ASP.NET WebApi实现依赖注入详细步骤总结
|
4月前
|
开发框架 .NET PHP
ASP.NET Web Pages - 添加 Razor 代码
ASP.NET Web Pages 使用 Razor 标记添加服务器端代码,支持 C# 和 Visual Basic。Razor 语法简洁易学,类似于 ASP 和 PHP。例如,在网页中加入 `@DateTime.Now` 可以实时显示当前时间。
下一篇
oss创建bucket