日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

如何理解 Web API

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

?

?什么是web API ?

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

?如圖1-1所示,發(fā)送請求,通過json的格式返回結(jié)果。

?

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

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

?ASP.Net web API的特性:

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

    ?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 = "獲取數(shù)據(jù)成功";}return result;}

    ?

    詳細說明:

    ? ? ? ??這是屬性路由的獲取數(shù)據(jù)的信息;

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

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

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

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

    ?

    ?

    HTTP方法:

    HttpPsot 、 HttpGet? 、HttpDelete 、 HttpPut.

    ?

    測試Web API

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

    ? ?Fildder

    ? ?posteman

    ?

    轉(zhuǎn)載于:https://www.cnblogs.com/qy1234/p/11028162.html

    總結(jié)

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

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。