You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/sp-add-ins/get-to-know-the-sharepoint-rest-service.md
+32-41Lines changed: 32 additions & 41 deletions
Original file line number
Diff line number
Diff line change
@@ -1,63 +1,62 @@
1
1
---
2
2
title: Get to know the SharePoint REST service
3
3
description: Basics of using the SharePoint REST service to access and update SharePoint data, using the REST and OData web protocol standards.
4
-
ms.date: 02/07/2018
4
+
ms.date: 1/15/2020
5
5
ms.prod: sharepoint
6
6
localization_priority: Priority
7
7
---
8
8
9
9
# Get to know the SharePoint REST service
10
10
11
-
SharePoint introduces a Representational State Transfer (REST) service that is comparable to the existing SharePoint [client object models](https://msdn.microsoft.com/library/88e5e1b9-eab2-4f3b-a3f2-75c96b86f1f4%28Office.15%29.aspx). Now, developers can interact remotely with SharePoint data by using any technology that supports REST web requests. This means that developers can perform **Create**, **Read**, **Update**, and **Delete** (CRUD) operations from their SharePoint Add-ins, solutions, and client applications, using REST web technologies and standard Open Data Protocol (OData) syntax.
11
+
SharePoint includes a Representational State Transfer (REST) service that is comparable to the existing SharePoint [client object models](/previous-versions/office/sharepoint-csom/jj193041(v=office.15)). Now, developers can interact remotely with SharePoint data by using any technology that supports REST web requests. This means that developers can perform **Create**, **Read**, **Update**, and **Delete** (CRUD) operations from their SharePoint Add-ins, solutions, and client applications, using REST web technologies and standard Open Data Protocol (OData) syntax.
12
12
13
13
## Prerequisites
14
14
15
15
This topic assumes you have a basic familiarity with REST and how to construct REST requests.
16
16
17
-
<aname="bk_how"> </a>
18
-
19
17
## How the SharePoint REST service works
20
18
21
19
SharePoint adds the ability for you to remotely interact with SharePoint sites by using REST. Now you can interact directly with SharePoint objects by using any technology that supports standard REST capabilities.
22
20
23
21
To access SharePoint resources using REST, construct a RESTful HTTP request by using the OData standard, which corresponds to the desired client object model API. For example:
GET https://{site_url}/_api/lists/getbytitle('{list_name}')/items
35
+
Authorization: "Bearer " + accessToken
36
+
Accept: "application/json;odata=verbose"
35
37
```
38
+
---
36
39
37
40
The client.svc web service in SharePoint handles the HTTP request, and serves the appropriate response in either Atom or JavaScript Object Notation (JSON) format. Your client application must then parse that response. The following figure shows a high-level view of the SharePoint REST architecture.
38
41
39
42
**SharePoint REST service architecture**
40
43
41
44

42
45
43
-
Because of the functionality and ease of use that client object models provide, they remain the primary development option for communicating with SharePoint sites by using .NET Framework managed code, Silverlight, or JavaScript.
44
-
45
-
<aname="bk_usingHTTP"> </a>
46
+
Because of the functionality and ease of use that client object models provide, they remain the primary development option for communicating with SharePoint sites by using the .NET Framework, Silverlight (*now deprecated*), or JavaScript (JSOM).
46
47
47
48
### Use HTTP commands with the SharePoint REST service
48
49
49
50
To use the REST capabilities that are built into SharePoint, you construct a RESTful HTTP request by using the OData standard, which corresponds to the client object model API you want to use. The client.svc web service handles the HTTP request and serves the appropriate response in either Atom or JSON format. The client application must then parse that response.
50
51
51
-
The endpoints in the SharePoint REST service correspond to the types and members in the SharePoint client object models. By using HTTP requests, you can use these REST endpoints to perform typical CRUD operations against SharePoint entities, such as lists and sites.
52
+
The endpoints in the SharePoint REST service correspond to the types and members in the SharePoint client object models. By using HTTP requests, you can use these REST endpoints to do typical CRUD operations against SharePoint entities, such as lists and sites.
52
53
53
54
|**If you want to do this to an endpoint**|**Use this HTTP request**|**Keep in mind**|
| Create or update a resource |**POST**| <ul><li>Use **POST** to create entities such as lists and sites.</li><li>The SharePoint REST service supports sending **POST** commands that include object definitions to endpoints that represent collections.</li><li>For **POST** operations, any properties that are not required are set to their default values.</li><li>If you attempt to set a read-only property as part of a **POST** operation, the service returns an exception.</li></ul> |
57
-
| Update or insert a resource |**PUT**| <ul><li>Use **PUT** and **MERGE** operations to update existing SharePoint objects.</li><li>Any service endpoint that represents an object property **set** operation supports both **PUT** requests and **MERGE** requests.</li><li>For **MERGE** requests, setting properties is optional; any properties that you do not explicitly set retain their current property.</li><li>For **PUT** requests, if you do not specify all required properties in object updates, the REST service returns an exception.</li><li>In addition, any optional properties you do not explicitly set are set to their default properties.</li></ul> |
58
-
| Delete a resource |**DELETE**| <ul><li>Use the HTTP **DELETE** command against the specific endpoint URL to delete the SharePoint object represented by that endpoint.</li><li>In the case of recyclable objects, such as lists, files, and list items, this results in a **Recycle** operation. </li></ul>|
59
-
60
-
<aname="bk_constructURLs"> </a>
57
+
| Create or update a resource |**POST**| <ul><li>Use **POST** to create entities such as lists and sites.</li><li>The SharePoint REST service supports sending **POST** commands that include object definitions to endpoints that represent collections.</li><li>For **POST** operations, any properties that aren't required are set to their default values.</li><li>If you attempt to set a read-only property as part of a **POST** operation, the service returns an exception.</li></ul> |
58
+
| Update or insert a resource |**PUT**| <ul><li>Use **PUT** and **MERGE** operations to update existing SharePoint objects.</li><li>Any service endpoint that represents an object property **set** operation supports both **PUT** requests and **MERGE** requests.</li><li>For **MERGE** requests, setting properties is optional; any properties that you don't explicitly set keep their current property.</li><li>For **PUT** requests, if you don't specify all required properties in object updates, the REST service returns an exception.</li><li>In addition, any optional properties you don't explicitly specify are set to their default properties.</li></ul> |
59
+
| Delete a resource |**DELETE**| <ul><li>Use the HTTP **DELETE** command against the specific endpoint URL to delete the SharePoint object represented by that endpoint.</li><li>There are recyclable objects, such as lists, files, and list items, this results in a **Recycle** operation. </li></ul>|
61
60
62
61
### Construct REST URLs to access SharePoint resources
63
62
@@ -66,13 +65,13 @@ Whenever possible, the URI for these REST endpoints closely mimics the API signa
66
65
To access a specific site collection, use the following construction:
67
66
68
67
```http
69
-
http://server/site/_api/site
68
+
https://{site_url}/_api/site
70
69
```
71
70
72
71
To access a specific site, use the following construction:
73
72
74
73
```http
75
-
http://server/site/_api/web
74
+
https://{site_url}/_api/web
76
75
```
77
76
78
77
In each case, *server* represents the name of the server, and *site* represents the name of, or path to, the specific site.
@@ -86,8 +85,6 @@ This syntax doesn't apply to the SocialFeedManager or SocialFollowingManager RES
86
85
87
86
For more guidelines for determining SharePoint REST endpoint URIs from the signature of the corresponding client object model APIs, see [Determine SharePoint REST service endpoint URIs](determine-sharepoint-rest-service-endpoint-uris.md).
88
87
89
-
<aname="bk_URLexamples"> </a>
90
-
91
88
## SharePoint REST endpoint examples
92
89
93
90
The following table contains typical REST endpoint URL examples to get you started working with SharePoint data. Prepend `http://server/site/_api/` to the URL fragments shown in the table to construct a fully qualified REST URL. Where necessary for **POST** commands, the table contains sample data you must pass in the HTTP request body to create the specified SharePoint item. Items in quotes represent variables that you must replace with your values.
@@ -106,38 +103,34 @@ The following table contains typical REST endpoint URL examples to get you start
106
103
107
104
```json
108
105
{
109
-
'__metadata': {
110
-
'type': 'SP.List'
106
+
"__metadata": {
107
+
"type": "SP.List"
111
108
},
112
-
'AllowContentTypes': true,
113
-
'BaseTemplate': 104 ,
114
-
'ContentTypesEnabled': true,
115
-
'Description': 'My list description ',
116
-
'Title': 'RestTest '
109
+
"AllowContentTypes": true,
110
+
"BaseTemplate": 104 ,
111
+
"ContentTypesEnabled": true,
112
+
"Description": "My list description ",
113
+
"Title": "RestTest "
117
114
}
118
115
```
119
116
120
117
**Adds an item to a list** sample data:
121
118
122
119
```json
123
120
{
124
-
'__metadata': {
125
-
'type': 'SP.Data.listname.ListItem'
121
+
"__metadata": {
122
+
"type": "SP.Data.listname.ListItem"
126
123
},
127
-
'Title': 'MyItem'
124
+
"Title": "MyItem"
128
125
}
129
126
```
130
127
131
128
In the above JSON, replace listname with the name of your SharePoint list by omitting the spaces.
132
129
133
-
<aname="batch"> </a>
134
-
135
130
## Batch job support
136
131
137
132
The SharePoint Online (and on-premises SharePoint 2016 or later) REST service supports combining multiple requests into a single call to the service by using the OData `$batch` query option. For details and links to code samples, see [Make batch requests with the REST APIs](make-batch-requests-with-the-rest-apis.md).
138
133
139
-
<aname="SP15startREST_bk_addlresources"> </a>
140
-
141
134
## OData resources
142
135
143
136
-[Developing Service-Oriented Applications with WCF](https://docs.microsoft.com/dotnet/framework/wcf/index)
@@ -147,8 +140,6 @@ The SharePoint Online (and on-premises SharePoint 2016 or later) REST service su
To learn more about using the SharePoint REST service, use the following resources.
@@ -158,7 +149,7 @@ To learn more about using the SharePoint REST service, use the following resourc
158
149
|[Complete basic operations using SharePoint REST endpoints](complete-basic-operations-using-sharepoint-rest-endpoints.md)| Perform basic create, read, update, and delete (CRUD) operations with the SharePoint REST interface. |
159
150
|[Working with lists and list items with REST](working-with-lists-and-list-items-with-rest.md)| Perform basic CRUD operations on lists and list items with the SharePoint REST interface. |
160
151
|[Working with folders and files with REST](working-with-folders-and-files-with-rest.md)| Perform basic CRUD operations on folders and files with the SharePoint REST interface. |
161
-
|[Navigate the SharePoint data structure represented in the REST service](navigate-the-sharepoint-data-structure-represented-in-the-rest-service.md)| Start from a REST endpoint for a given SharePoint item, and navigate to and accessrelated items, such as parent sites or the library structure where that item resides. |
152
+
|[Navigate the SharePoint data structure represented in the REST service](navigate-the-sharepoint-data-structure-represented-in-the-rest-service.md)| Start from a REST endpoint for a given SharePoint item, and navigate to and access-related items, such as parent sites or the library structure where that item resides. |
162
153
|[Determine SharePoint REST service endpoint URIs](determine-sharepoint-rest-service-endpoint-uris.md)| General guidelines for determining SharePoint REST endpoint URIs from the signature of the corresponding client object model APIs. |
163
154
|[Use OData query operations in SharePoint REST requests](use-odata-query-operations-in-sharepoint-rest-requests.md)| Use a wide range of OData query string operators to select, filter, and order the data you request from the SharePoint REST service. |
164
155
|[Make batch requests with the REST APIs](make-batch-requests-with-the-rest-apis.md)| Combine multiple requests into a single call to the REST service. |
0 commit comments