1. 程式人生 > >API和web API

API和web API

API

Apis (Application Programming interfaces) are predefined functions designed to provide applications and developers the ability to access a set of routines based on a piece of software or hardware without having to access source code or understand the details of the internal workings.

 

Web API

ASP.NET Web API是一個框架,它使構建HTTP服務變得很容易,這些服務可以到達廣泛的客戶端,包括瀏覽器和移動裝置。ASP.NET Web API是在.NET框架上構建基於rest的應用程式的理想平臺。

目的:

Web API最重要的是可以構建面向各種客戶端的服務。另外與WCF REST Service不同在於,Web API利用Http協議的各個方面來表達服務(例如 URI/request response header/caching/versioning/content format),因此就省掉很多配置。

功能簡介
1、支援基於Http verb (GET, POST, PUT, DELETE)的CRUD (create, retrieve, update, delete)操作

通過不同的http動作表達不同的含義,這樣就不需要暴露多個API來支援這些基本操作。

2、請求的回覆通過Http Status Code表達不同含義,並且客戶端可以通過Accept header來與伺服器協商格式,例如你希望伺服器返回JSON格式還是XML格式。

3、請求的回覆格式支援 JSON,XML,並且可以擴充套件新增其他格式。

4、原生支援OData。

5、支援Self-host或者IIS host。

6、支援大多數MVC功能,例如Routing/Controller/Action Result/Filter/Model Builder/IOC Container/Dependency Injection。