博客地址:http://blog.csdn.net/FoxDave

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 area Access point
Site http:// server/site/_api/site
Web http:// server/site/_api/web
User Profile http:// server/site/_api/SP.UserProfiles.PeopleManager
Search http:// server/site/_api/search

访问你想要访问的指定资源

根据客户端对象模型来构建REST服务访问你想要访问的资源,如下表。

**Client object model API ** REST endpoint
ClientContext.Web.Lists http:// 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的更多相关文章

  1. Windows 商店应用中使用 SharePoint REST API

    前面一篇我们介绍了 Office 365 REST API 的官方工具的使用,本篇我们来看一下 SharePoint REST API 本身的描述.结构和使用方法,以及一些使用经验. 首先来看看Sha ...

  2. [sharepoint]Rest api相关知识(转)

    写在前面 最近又开始弄rest api了,通过sharepoint rest api获取站点信息,Items,fields非常方便,再结合OData查询,更是得心应手.这里记录学习的时候用到的知识点, ...

  3. SharePoint REST API - 基本操作(二)

    博客地址:http://blog.csdn.net/FoxDave 上一节讲了SharePoint REST API的一些基本操作,本节将继续介绍一些关于SharePoint REST API的内容. ...

  4. SharePoint REST API - 概述

    博客地址:http://blog.csdn.net/FoxDave SharePoint REST API不同于传统的Server Object Model和Client Object Model ...

  5. How to Call SharePoint 2013 API Service to Query The Lists

    How to Call SharePoint 2013 API In SharePoint 2013, we can query the list by it owner service, then ...

  6. SharePoint REST api

    http://msdn.microsoft.com/en-us/magazine/dn198245.aspx Understanding and Using the SharePoint 2013 R ...

  7. [sharepoint]rest api文档库文件上传,下载,拷贝,剪切,删除文件,创建文件夹,修改文件夹属性,删除文件夹,获取文档列表

    写在前面 最近对文档库的知识点进行了整理,也就有了这篇文章,当时查找这些接口,并用在实践中,确实废了一些功夫,也为了让更多的人走更少的弯路. 系列文章 sharepoint环境安装过程中几点需要注意的 ...

  8. SharePoint REST API - 基本操作(一)

    博客地址:http://blog.csdn.net/FoxDave 本文讲述如何应用SharePoint的REST接口完成基本的增删查改操作. 使用SharePoint客户端API和REST服务进 ...

  9. SharePoint JavaScript API in application pages

    前言 最近,在SharePoint 应用程序页中写JavaScript API,进行一些数据交互.其实,很简单的事情却遇到了问题,记录一下,希望能对遇到类似问题的人以帮助. 引用JavaScript ...

随机推荐

  1. Vue.js总结 [2017.6.5]

    <head> <script src="https://unpkg.com/vue/dist/vue.js"></script> </he ...

  2. Composer 的autoload 实现

    require_once './vendor/autoload.php'; 一.autoload.php 加载 composer/autoload_real.php 调用 autoload_real. ...

  3. python基础之函数参数,名称空间,以及函数嵌套

    函数进阶内容梗概: 1. 函数参数--动态传参 2. 名称空间, 局部名称空间, 全局名称空间, 作⽤用域, 加载顺序. 3. 函数的嵌套 4. gloabal , nonlocal 关键字 1. 函 ...

  4. 背包DP 存在异或条件的状态转移问题

    题目链接 分析:有大佬说可以用线性基写,可惜我不会,这是用DP写的 题目明确说明可到达的位置只与能值有关,和下标无关,我们就可以排个序,这样每个数可以转移的区间就是它的所有后缀 我们可以用dp[i][ ...

  5. bootstrap fileinput组件的使用

    组件的下载地址为:https://github.com/kartik-v/bootstrap-fileinput 比较详细的介绍可参看:http://www.jq22.com/jquery-info5 ...

  6. Fiddler 抓包工具总结【转载】

    原博主连接在文章底部 Fiddler是一个蛮好用的抓包工具,可以将网络传输发送与接受的数据包进行截获.重发.编辑.转存等操作.也可以用来检测网络安全.反正好处多多,举之不尽呀!当年学习的时候也蛮费劲, ...

  7. js中用来操作字符串的相关的方法

    var str = "zhufengpeixun2015yangfanqihang"; 字符串也是存在索引和length的 str.length 获取字符串的长度(字符的个数) 第 ...

  8. JavaScript中 null 的 typeof是object

    JavaScript中  null 的 typeof是object

  9. spring boot cloud

    eclipse spring boot 项目创建 https://www.cnblogs.com/shuaihan/p/8027082.html https://www.cnblogs.com/LUA ...

  10. Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置

    The following code examples are extracted from open source projects. You can click  to vote up the e ...