webApi实践:开始WebApi 2

 

1.学习步骤总结

学习网址:http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

 

主要的步骤路线:

 

 

2.分析

 

VS2013,WebApi。

 

2.1异步模式的响应

  1. public interface IHttpActionResult
  2.     {
  3.         Task<System.Net.Http.HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken);
  4.     }

 

2.2 HTTP消息结构封装:

 

2.3 NotFound,Ok

  1. public IHttpActionResult GetProduct(int id)
  2. {
  3.     var product = products.FirstOrDefault(zw => zw.Id == id);
  4.     if(product == null)
  5.     {
  6.         return NotFound();
  7.     }
  8.  
  9.     return Ok(product);
  10. }

 

2.4 jquery

 

  1. $.getJSON(uri)
  2.                 .done(function (data) {
  3.                     // On success, 'data' contains a list of products.
  4.                     $.each(data, function (key, item) {
  5.                         // Add a list item for the product.
  6.                         $('<li>', { text: formatItem(item) }).appendTo($('#products'));
  7.                     });
  8.                 });
原文地址:https://www.cnblogs.com/pengzhen/p/4900037.html