博客地址: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. 有序广播和标准广播 --Android开发

    一.标准广播和有序广播也很容易理解的. 标准广播: (1)通过sendBroadcast()方法发送 (2)通过异步方式发送,广播接收者的执行顺序是不明确的 有序广播: (1)通过sendOrderB ...

  2. 分享基于EF+WCF的通用三层架构及解析

    本项目结合EF 4.3及WCF实现了经典三层架构,各层面向接口,WCF实现SOA,Repository封装调用,在此基础上实现了WCFContext,动态服务调用及一个分页的实例. 1. 项目架构图: ...

  3. hdu-4632 Palindrome subsequence (回文子序列计数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 问题要求回答一串字符串中回文子序列的数量,例如acbca就有 a,c,b,c,a,cc,aa,a ...

  4. mysql防注入

    1.对用户输入的数据进行过滤 2.永远不要使用动态拼装sql,可以使用参数化的sql或者直接使用存储过程进行数据查询存取. 3.永远不要使用管理员权限的数据库连接,为每个应用使用单独的权限有限的数据库 ...

  5. nginx-exporter安装使用

    一.没有vts的启动方式   #nginx_exporter -telemetry.address=:9113 -nginx.scrape_uri="http://127.0.0.1:100 ...

  6. 【MySQL】【1】表中存在重复记录,删除保留其中一条

    --删除题库(TABLE_Q )中,标题(TITLE )和类型(TYPE )都相同的数据,仅保留ID最小的一条 DELETE TABLE_Q FROM TABLE_Q, ( ) T2 WHERE TA ...

  7. python_递归实现汉诺塔 (string类型的指针出错 未解决)

    在递归的时候,和数学的归纳法一致. void func( mode) { if(endCondition) { constExpression //基本项 } else { accumrateExpr ...

  8. poj-2888-矩阵+polya

    Magic Bracelet Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 6195   Accepted: 1969 D ...

  9. echarts3 使用总结

    由于项目需要自学了echarts,下面将学到的东西总结如下,如果有哪里写的不好,请批评指正 一.前期准备 1.使用echarts之前先要引入echarts.js,js可以到官网下载 2.写一个div容 ...

  10. Lexicography

    An anagram of a string is any string that can be formed using the same letters as the original. (We ...