日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

如何理解 Web API

發布時間:2025/5/22 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何理解 Web API 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 什么是web API?
  • web API 控制器、路由
  • 測試? Web? API

?

?什么是web API ?

?簡單說,API是接口,訪問程序的某一個功能或者數據,實現移動端和客戶端的程序之間的數據交互;web API,是可以通過HTTP的協議訪問的web的上的API。

?如圖1-1所示,發送請求,通過json的格式返回結果。

?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 圖1-1

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

?ASP.Net web API的特性:

  • ASP.NET Web API是構建RESTful服務的理想平臺。
  • ASP.NET Web API構建于ASP.NET之上,支持ASP.NET請求/響應管道
  • ASP.NET Web API將HTTP謂詞映射到方法名稱。
  • ASP.NET Web API支持不同格式的響應數據。內置支持JSON,XML,BSON格式。
  • ASP.NET Web API可以托管在IIS,自托管或支持.NET 4.0+的其他Web服務器中。
  • ASP.NET Web API框架包括用于與Web API服務器通信的新HttpClient。HttpClient可用于ASP.MVC服務器端,Windows窗體應用程序,控制臺應用程序或其他應用程序。
  • ?

    ?Web API 控制器、路由

    ?

    [RoutePrefix("data")] public class CNCheckerController : InitXpoController{[Route("GetAllOldEquipments")][HttpGet]public Result<List<AppOldEquipmentInfo>> GetAllOldEquipments(string Brand, string ModuleType, Palatfromtype PlatformTypes, int pageSize, int Page){Result<List<AppOldEquipmentInfo>> result = new Result<List<AppOldEquipmentInfo>>();result.Data = new List<AppOldEquipmentInfo>();using (Session){GroupOperator groupOperator = new GroupOperator(GroupOperatorType.And);if (!string.IsNullOrEmpty(Brand))groupOperator.Operands.Add(new BinaryOperator("FBrand", Brand));if (!string.IsNullOrEmpty(ModuleType))groupOperator.Operands.Add(new BinaryOperator("FModuleType", ModuleType));groupOperator.Operands.Add(CriteriaOperator.Parse("FPlatformTypes", PlatformTypes));groupOperator.Operands.Add(CriteriaOperator.Parse("ture"));var Searcholdequipment = new XPCollection<B_oldequipment>(Session, groupOperator, new SortProperty("createdate", DevExpress.Xpo.DB.SortingDirection.Descending)){ TopReturnedObjects = pageSize, SkipReturnedObjects = pageSize * Page };foreach (var oldequ in Searcholdequipment){AppOldEquipmentInfo appoldequipment = new AppOldEquipmentInfo();appoldequipment.Init(oldequ);result.Data.Add(appoldequipment);}result.Successed = true;result.Msg = "獲取數據成功";}return result;}

    ?

    詳細說明:

    ? ? ? ??這是屬性路由的獲取數據的信息;

    ? ? ? ? ? ①? [RoutePrefix]: 整個控制器設置公共前綴

    ? ? ? ? ? ②? Route: 控制器中的路由

    ? ? ? ? ? ③?HttpGet:請求的方法

    ? ? ? ? ? ④ 路由url:?[RoutePrefix]+【Route】是請求API的url地址

    ?

    ?

    HTTP方法:

    HttpPsot 、 HttpGet? 、HttpDelete 、 HttpPut.

    ?

    測試Web API

    開發web API在本地進行測試,我們可以使用以下第三方工具來測試Web API或者在 web API頁面上進行測試。

    ? ?Fildder

    ? ?posteman

    ?

    轉載于:https://www.cnblogs.com/qy1234/p/11028162.html

    總結

    以上是生活随笔為你收集整理的如何理解 Web API的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。