菜单
  
    Introduction to ASP.NET Web API Introduction ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. With Web API content negotiation, we can return data based on the client requests. What I mean is, if the client is requesting the data to be returned as JSON or XML, the Web API framework deals with the request type and returns the data appropriately based on the media type. By default Web API provides JSON and XML based responses.39923
    Web API is an ideal platform for building pure HTTP based services where the request and response happens with HTTP protocol. The client can make a GET, PUT, POST, and DELETE request and get the Web API response appropriately.
    In summary, the Web API is
    •    An HTTP Service
    •    Designed for broad reach
    •    Uses HTTP as an Application protocol, not a transport protocol
    Web API Architecture
    We shall see below the Web API architecture when you are hosting Web API in ASP.NET and self-hosting through console or Windows service.
    Routing configuration in Web API is slightly different from asp.NET MVC Routing. The Web API uses Http Route Collection and Route. The Web API team has reused the routing logic of MVC in Web API. The only reason why it’s a different routing is in order to keep the Web API from having its dependency onasp.NET Routing. The team decided to make it independent so that Web API will not haveasp.NET class dependencies and it can be hosted in console or a Windows service as self-hosting.
    While inasp.NET Web API Routing, the system will not only register the Http Route object but also it will create a wrapper Route object and in the asp.NET routing engine.
    The significant difference that you can see here is you will not have access to Routing data in message handlers when you are trying to access the same in self-hosting, the reason is the route configuration is set and it will run at a later point in the life cycle.
    The other significant difference between the API Controller and the normal MVC controller is with Web API , API Controller, the actions are dispatched by default based on the HTTP request. However there is a flexibility to override it so that the Web API will use the action name to select the action method within the API Controller.
    What is Content Negotiation in Web API
    This is something which you will here frequently in Web API. Content negotiation is the process of selecting the best representation for a given response when there are multiple representations available. The underling Web API framework implements the content negotiation and that is the reason why and how the client can request data with a specific media type.
    By default the Web API returns data in JSON format, however while requesting for a resource, we can specify the media type to return so that the Web API knows what you are requesting for and select the proper formatter to output the data.
    How to Implement Web API?
    We shall see a generic implementation of Web API.
    We have to create a class which derives from API Controller. The methods defined in the Web API controller map to the HTTP methods. If you have a method name prefixed with GET, it means you are trying to return some data based upon the GET request. You just have to make sure that whatever actions you are implementing must be prefixed with the right request type (GET, POST, PUT, and DELETE).
    Note: The method name need not be Get () or Post () etc. However it does not limit to prefixing the request types. You can still implement the actions with different naming but you have to make sure to use the suitable action filters [Http Get], [Post], [Put], [Delete].
    Background
    This article is just a start of a beginner article for Web API. A basic understanding of MVC is sufficient to understand and implement asp.NET Web API.
     B.原文的翻译
  1. 上一篇:JDBC-Spring框架英文文献和中文翻译
  2. 下一篇:JSP技术的发展历程英文文献和中文翻译
  1. 机械手系统英文文献和中文翻译

  2. MySQL和JSP的Web应用程序英文文献和中文翻译

  3. 基于SSH的web技术英文文献和中文翻译

  4. Java技术的Web应用设计模型...

  5. ASP.NET技术先进的控件编程...

  6. Web2.0的网络广告模式英文文献和中文翻译

  7. 从经典ASP到ASP.NET英文文献和中文翻译

  8. C++最短路径算法研究和程序设计

  9. 上市公司股权结构对经营绩效的影响研究

  10. 江苏省某高中学生体质现状的调查研究

  11. 巴金《激流三部曲》高觉新的悲剧命运

  12. 现代简约美式风格在室内家装中的运用

  13. NFC协议物理层的软件实现+文献综述

  14. g-C3N4光催化剂的制备和光催化性能研究

  15. 浅析中国古代宗法制度

  16. 中国传统元素在游戏角色...

  17. 高警觉工作人群的元情绪...

  

About

优尔论文网手机版...

主页:http://www.youerw.com

关闭返回