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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SharePoint REST API - 确定REST端点URL

發布時間:2023/12/10 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SharePoint REST API - 确定REST端点URL 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

SharePoint REST端點URI的結構

在你能夠通過REST訪問SharePoint資源之前,首先你要做的就是找出對應的URI端點,如果你對Client API熟悉,有些時候也可以參考Client API去猜測構建,例如。

客戶端對象模型的方法:

?

List.GetByTitle(listname).GetItems()

對應的REST端點URI為:

http://server/site/_api/lists/getbytitle('listname')/items

然而為了遵守REST和OData標準,REST端點和Client API不總是一致的。下圖展示了REST API的一般語法結構。

?

訪問某些SharePoint資源的API跟此語法結構不太一致,它們是:

>需要復雜類型參數的方法

>靜態方法和屬性

確定SharePoint REST服務的端點

構建一個訪問SharePoint資源的REST端點可以遵循下面的步驟:

1. 開始一段REST服務引用 http://server/site/_api

2. 指定適當的入口,如Web?http://server/site/_api/web

3. 指定要訪問的具體資源,這通常跟客戶端對象模型是一致的?http://server/site/_api/web/lists/getbytitle('listname')

在你的URI端點中引用你的SharePoint REST服務

使用_api來表示SharePoint REST服務,REST服務是client.svc網絡服務的一部分,REST是為了簡化所以改用_api來表示。也就是說,http://server/site/_vti_bin/client.svc/web/lists和http://server/site/_api/web/lists這兩種格式是都被支持的,但是推薦使用_api這種方式,因為URL有256個字符的限制。

指定SharePoint REST服務的入口

REST服務的主入口表示網站集合上下文對象(context)對應的網站,這跟ClientContext.Site和ClientContext.Web這兩個屬性一致。

如果要訪問一個指定的網站集,使用http://server/site/_api/site。如果要訪問一個指定的網站,使用http://server/site/_api/web。下表是一個對應關系。

?

Feature areaAccess point
Sitehttp:// server/site/_api/site
Webhttp:// server/site/_api/web
User Profilehttp:// server/site/_api/SP.UserProfiles.PeopleManager
Searchhttp:// server/site/_api/search

訪問你想要訪問的指定資源

根據客戶端對象模型來構建REST服務訪問你想要訪問的資源,如下表。

?

**Client object model API **REST endpoint
ClientContext.Web.Listshttp:// server/ site/_api/web/lists
ClientContext.Web.Lists[guid]http:// server/ site/_api/web/lists(' guid')
ClientContext.Web.Lists.GetByTitle("Title")http:// server/ site/_api/web/lists/getbytitle(' Title')

在REST端點URI中指定參數

SharePoint擴展了OData規范使你能夠使用括號來指定方法的參數和索引下標值。這防止了在URI中包含多個同名參數時潛在的不明確問題。例如http://server/site/_api/web/lists/getByTitle('Announcements')/fields/getByTitle('Description')和http://server/site/_api/web/lists('<guid>')/fields/getById('<guid>')。

如果參數是一個鍵值對,那么就用逗號分隔一下,如http://server/site/_api/web/getAvailableWebTemplates(lcid=1033, includeCrossLanguage=true)。

REST服務中的復雜參數類型

在客戶端對象模型的一些方法中需要大數據作為參數,REST也提供了這種能力,但是不在URL上,而是通過POST操作。例如,ListCollection.Add方法需要Microsoft.SharePoint.Client.ListCreationInformation作為參數,需要構建如下的請求:

http://server/site/_api/web/lists/add

?

{ "d" : {"results": {"__metadata": {"type": "SP.ListCreationInformation"}, "CustomSchemaXml": "…large payload…/", "Description": "desc", "DocumentTemplateType": "1", "TemplateType": "101", "Title": "Announcements"} } }

在REST服務請求中使用別名

?

你可以定義參數別名去請求SharePoint REST,直接用示例說明。

直接請求的樣子:http://server/site/_api/web/applyWebTemplate("STS#0")

使用別名的樣子:http://server/site/_api/web/applyWebTemplate(title=@template)?@template="STS#0"

需要注意一下這種方式不支持復雜的參數,即http://server/site/_api/userProfiles/People(7)/GetWorkplace(@address)?@address={"__metadata":{"type: "ODataDemo.Address"},"Street":"NE 228th", "City":"Sammamish","State":"WA","ZipCode":"98074","Country": "USA"}這樣的是不被支持的。

在REST服務URI中使用靜態方法和屬性

構建一個靜態方法或屬性的REST服務URI,可以使用與ECMAScript對象模型中一致的API名字,如http://server/site/_api/SP.Utilities.Utility.getImageUrl('imageName')。需要注意的是這種方式不能作為參數來傳遞而只能直接調用,舉個例子說明:

http://server/site/_api/SP.Utility.assetsLibrary/id是可以的,但是http://server/site/_api/getList(~SP.Utility/assetsLibrary/id)就不行。

本篇就講到這里。

總結

以上是生活随笔為你收集整理的SharePoint REST API - 确定REST端点URL的全部內容,希望文章能夠幫你解決所遇到的問題。

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