1.学习步骤总结
学习网址:http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
主要的步骤路线:
2.分析
VS2013,WebApi。
2.1异步模式的响应
- public interface IHttpActionResult
- {
- Task<System.Net.Http.HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken);
- }
2.2 HTTP消息结构封装:
2.3 NotFound,Ok
- public IHttpActionResult GetProduct(int id)
- {
- var product = products.FirstOrDefault(zw => zw.Id == id);
- if(product == null)
- {
- return NotFound();
- }
- return Ok(product);
- }
2.4 jquery
- $.getJSON(uri)
- .done(function (data) {
- // On success, 'data' contains a list of products.
- $.each(data, function (key, item) {
- // Add a list item for the product.
- $('<li>', { text: formatItem(item) }).appendTo($('#products'));
- });
- });