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/spfx/connect-to-anonymous-apis.md
+7-5Lines changed: 7 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Connect to anonymous APIs
3
3
description: Different approaches of connecting to anonymous APIs from your SharePoint Framework solutions
4
-
ms.date: 10/23/2018
4
+
ms.date: 12/04/2020
5
5
ms.prod: sharepoint
6
6
localization_priority: Priority
7
7
---
@@ -28,7 +28,9 @@ this.context.httpClient
28
28
});
29
29
```
30
30
31
-
Similarly to the SPHttpClient you use for connecting to SharePoint APIs, the HttpClient offers you similar capabilities for performing the most common web requests. If necessary, you can use its options, to configure requests. For example, to specify request headers, you would use the following code:
31
+
Similarly to the **SPHttpClient** you use for connecting to SharePoint APIs, the **HttpClient** offers you similar capabilities for running the most common web requests. If necessary, you can use its options, to configure requests.
32
+
33
+
For example, to specify request headers, you would use the following code:
32
34
33
35
```typescript
34
36
this.context.httpClient
@@ -48,12 +50,12 @@ this.context.httpClient
48
50
49
51
### Considerations for using the HttpClient
50
52
51
-
When using the HttpClient, there are a few things that you should take into account.
53
+
When using the **HttpClient**, there are a few things that you should take into account.
52
54
53
55
#### Authentication cookies not included
54
56
55
-
While the HttpClient is very similar to the SPHttpClient, it doesn't include authentication cookies in its requests. So if you were to use it to connect to SharePoint APIs, your requests would fail with a 401 Unauthorized response.
57
+
While the **HttpClient** is similar to the **SPHttpClient**, it doesn't include authentication cookies in its requests. So if you were to use it to connect to SharePoint APIs, your requests would fail with a 401 Unauthorized response.
56
58
57
59
#### Part of the SharePoint Framework
58
60
59
-
The HttpClient is part of the SharePoint Framework and you don't need any additional dependencies to start using it. It is already available on the page which is why using it doesn't cause additional performance overhead on runtime.
61
+
The **HttpClient** is part of the SharePoint Framework and you don't need any additional dependencies to start using it. It is already available on the page that is why using it doesn't cause additional performance overhead on runtime.
Copy file name to clipboardExpand all lines: docs/spfx/connect-to-sharepoint.md
+15-15Lines changed: 15 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,18 @@
1
1
---
2
2
title: Connect to SharePoint APIs
3
3
description: Different approaches of connecting to SharePoint APIs from your SharePoint Framework solutions
4
-
ms.date: 10/19/2020
4
+
ms.date: 12/04/2020
5
5
ms.prod: sharepoint
6
6
localization_priority: Priority
7
7
---
8
8
9
9
# Connect to SharePoint APIs
10
10
11
-
In your SharePoint Framework solutions, you will likely want to interact with data stored in SharePoint. SharePoint offers a rich set of APIs that can be consumed in various ways. This article outlines what options you have, how they work and what their advantages and disadvantages are.
11
+
In your SharePoint Framework solutions, you'll likely want to interact with data stored in SharePoint. SharePoint offers a rich set of APIs that can be consumed in various ways. This article outlines what options you have, how they work and what their advantages and disadvantages are.
12
12
13
13
## Connect to SharePoint API using the SPHttpClient
14
14
15
-
SharePoint Framework offers the SPHttpClient that you can use to connect to SharePoint REST APIs. A ready-to-use instance of the SPHttpClient is available on the web part/extension context and you can use it to perform all kinds of web request. Following code snippet shows how you would use the SPHttpClient to retrieve the title of the current site:
15
+
SharePoint Framework offers the SPHttpClient that you can use to connect to SharePoint REST APIs. A ready-to-use instance of the SPHttpClient is available on the web part/extension context and you can use it to do all kinds of web request. Following code snippet shows how you would use the SPHttpClient to retrieve the title of the current site:
16
16
17
17
```typescript
18
18
this.context.spHttpClient
@@ -25,7 +25,7 @@ this.context.spHttpClient
25
25
});
26
26
```
27
27
28
-
The SPHttpClient offers basic functionality for performing the most common web requests. It allows you also, to configure your request by for example specifying request headers. For example, if you wanted to issue a web request without retrieving metadata, you'd use the following code:
28
+
The SPHttpClient offers basic functionality for performing the most common web requests. It allows you also, to configure your request by, for example, specifying request headers. For example, if you wanted to issue a web request without retrieving metadata, you'd use the following code:
29
29
30
30
```typescript
31
31
this.context.spHttpClient
@@ -46,11 +46,11 @@ this.context.spHttpClient
46
46
47
47
### Considerations for using the SPHttpClient
48
48
49
-
When using the SPHttpClient there are a few things that you should take into account.
49
+
When using the SPHttpClient, there are a few things that you should take into account.
50
50
51
51
#### OData v4.0
52
52
53
-
By default, the SPHttpClient uses OData v4 specification, which requires using `odata.metadata` instead of just `odata` to control the response metadata. If you use the `odata` directive in OData v4 mode, you will get an error, like: _The HTTP header ACCEPT is missing or its value is invalid._. It is possible to set the SPHttpClient to OData v3.0 mode, by setting the `odata-version` request header to empty value:
53
+
By default, the SPHttpClient uses OData v4 specification, which requires using `odata.metadata` instead of just `odata` to control the response metadata. If you use the `odata` directive in OData v4 mode, you'll get an error, like: _The HTTP header ACCEPT is missing or its value is invalid._. It is possible to set the SPHttpClient to OData v3.0 mode, by setting the `odata-version` request header to empty value:
54
54
55
55
```typescript
56
56
this.context.spHttpClient
@@ -72,15 +72,15 @@ this.context.spHttpClient
72
72
73
73
#### Authentication cookies
74
74
75
-
In the SharePoint Framework there are a number of classes for executing web requests. Two of them are the **SPHttpClient** and **HttpClient**. One of the differences between the SPHttpClient and HttpClient is that the SPHttpClient includes authentication cookies when issuing web requests. Because SharePoint APIs are not anonymous, you need to provide authentication information or you will get an 401 Unauthorized response. Because the HttpClient doesn't include authentication cookies in its request, if you used it to call the SharePoint REST APIs, your requests would fail with a 401 Unauthorized response.
75
+
In the SharePoint Framework, there are a number of classes for executing web requests. Two of them are the **SPHttpClient** and **HttpClient**. One of the differences between the SPHttpClient and HttpClient is that the SPHttpClient includes authentication cookies when issuing web requests. Because SharePoint APIs are not anonymous, you need to provide authentication information or you'll get an 401 Unauthorized response. Because the HttpClient doesn't include authentication cookies in its request, if you used it to call the SharePoint REST APIs, your requests would fail with a 401 Unauthorized response.
76
76
77
77
#### Part of the SharePoint Framework
78
78
79
-
The SPHttpClient is part of the SharePoint Framework and you don't need any additional dependencies to start using it. It is already available on the page which is why using it doesn't cause additional performance overhead on runtime.
79
+
The SPHttpClient is part of the SharePoint Framework and you don't need any additional dependencies to start using it. It is already available on the page that is why using it doesn't cause additional performance overhead on runtime.
80
80
81
81
#### Raw REST queries are error-prone
82
82
83
-
The SPHttpClient offers basic support for communicating with the SharePoint REST API. If your applications requires more complex GET requests, POST requests or uses more advanced capabilities such as batching, you will quickly notice that using the SPHttpClient is cumbersome and error-prone. In such cases, you should consider using an alternative such as the PnPjs library that offers you a fluent API that can be verified for correctness by TypeScript.
83
+
The SPHttpClient offers basic support for communicating with the SharePoint REST API. If your applications require more complex GET requests, POST requests or uses more advanced capabilities such as batching, you'll quickly notice that using the SPHttpClient is cumbersome and error-prone. In such cases, you should consider using an alternative such as the PnPjs library that offers you a fluent API that can be verified for correctness by TypeScript.
Notice, how less verbose the code is comparing to the SharePoint Framework SPHttpClient and how all elements of the requests, except for the names of the properties to retrieve, are strongly-typed lowering the risk of runtime errors.
100
+
Notice, how less verbose the code is comparing to the SharePoint Framework SPHttpClient and how all elements of the requests, except for the names of the properties to retrieve, are stronglytyped lowering the risk of runtime errors.
101
101
102
-
For more information about how to setup and use PnPjs in the SharePoint Framework see the PnPjs documentation at [https://pnp.github.io/pnpjs/](https://pnp.github.io/pnpjs/).
102
+
For more information about how to setup and use PnPjs in the SharePoint Framework, see the PnPjs documentation at [https://pnp.github.io/pnpjs/](https://pnp.github.io/pnpjs/).
103
103
104
104
### Considerations for using PnPjs
105
105
106
106
When deciding whether you should use PnPjs or not, following are a few considerations that you should take into account.
107
107
108
108
#### Raw REST queries are error prone
109
109
110
-
Issuing raw REST requests using the SPHttpClient is error-prone. Especially, when your application will need to execute POST queries or you will want to use some of the more advanced capabilities such as request batching, composing the correct requests and parsing the responses will be cumbersome. Not to mention, the only way to verify if the requests are correct is by running the code in the browser. With PnPjs you can communicate with SharePoint APIs in a type-safe way and easily use the advanced capabilities of SharePoint API what allows you to focus on building your application instead of testing its requests.
110
+
Issuing raw REST requests using the SPHttpClient is error-prone. Especially, when your application will need to execute POST queries or you'll want to use some of the more advanced capabilities such as request batching, composing the correct requests and parsing the responses will be cumbersome. Not to mention, the only way to verify if the requests are correct is by running the code in the browser. With PnPjs, you can communicate with SharePoint APIs in a type-safe way and easily use the advanced capabilities of SharePoint API what allows you to focus on building your application instead of testing its requests.
111
111
112
112
#### Open-source project
113
113
114
-
PnPjs is an open-source project managed by the SharePoint community. There is no SLA for using PnPjs in your solutions and Microsoft support won't assist you with any possible issues when caused by PnPjs. That said, PnPjs is actively developed and the community quickly responds to all submitted issues and questions.
114
+
PnPjs is an open-source project managed by the SharePoint community. There's no SLA for using PnPjs in your solutions and Microsoft support won't assist you with any possible issues when caused by PnPjs. That said, PnPjs is actively developed and the community quickly responds to all submitted issues and questions.
115
115
116
116
#### Additional dependency
117
117
118
-
PnPjs is an additional dependency that you need to add to your project and manage over time. You need to keep track of its updates and upgrade your project when necessary. The community behind PnPjs regularly communicates the state of the current work, upcoming releases and the impact, if any, of upgrading to the newer version.
118
+
PnPjs is an additional dependency that you need to add to your project and manage over time. You need to keep track of its updates and upgrade your project when necessary. The community behind PnPjs regularly communicates the state of the current work, upcoming releases, and the impact, if any, of upgrading to the newer version.
119
119
120
120
#### Additional payload
121
121
122
-
PnPjs offers a rich set of capabilities for communicating with SharePoint APIs. But these capabilities add extra load to your project. Compressed, PnPjs will add ~40KB to the generated bundle size.
122
+
PnPjs offers a rich set of capabilities for communicating with SharePoint APIs. But these capabilities add extra load to your project. Compressed, PnPjs will add ~40 KB to the generated bundle size.
Copy file name to clipboardExpand all lines: docs/spfx/subscribe-to-list-notifications.md
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,26 @@
1
1
---
2
2
title: Subscribe to list notifications
3
3
description: Get notified and respond to changes to files in SharePoint Document Libraries
4
-
ms.date: 12/10/2019
4
+
ms.date: 12/04/2020
5
5
ms.prod: sharepoint
6
6
localization_priority: Normal
7
7
---
8
8
9
9
# Subscribe to list notifications
10
10
11
-
Starting from SharePoint Framework v1.7.0, you can subscribe to changes to files stored in a SharePoint Document Library. This allows you to respond to changes when they happen, without having to regularly poll the contents of the library.
11
+
Introduced in SharePoint Framework v1.7.0, you can subscribe to changes to files stored in a SharePoint Document Library. This allows you to respond to changes when they happen, without having to regularly poll the contents of the library.
12
12
13
13
## Prerequisites
14
14
15
-
To use the SharePoint Framework list subscription capability, you first need to install the `@microsoft/sp-list-subscription` npm package. You can do it using the following code snippet:
15
+
To use the SharePoint Framework list subscription capability, you first need to install the **@microsoft/sp-list-subscription** npm package. You can do it using the following code snippet:
## Get notified of changes to documents stored in a SharePoint Document Library
22
22
23
-
To subscribe to changes to files stored in a SharePoint Document Library, create an instance of the `ListSubscriptionFactory` class. Next, call the `createSubscription` method passing the ID of the Document Library to which you want to subscribe. If the Document Library is located in the current site, it's sufficient to specify just the library ID. If it's located in a different site or site collection, then you need to specify their ID's as well.
23
+
To subscribe to changes to files stored in a SharePoint Document Library, create an instance of the `ListSubscriptionFactory` class. Next, call the `createSubscription()` method passing the ID of the Document Library to which you want to subscribe. If the Document Library is located in the current site, it's sufficient to specify just the library ID. If it's located in a different site or site collection, then you need to specify their IDs as well.
24
24
25
25
Following, is an example of a list subscription for a Document Library located in the current site:
### Get notified when the subscription has been established or cancelled
75
+
### Get notified when the subscription has been established or canceled
76
76
77
77
In some cases, you might want to get notified when the component that you're building successfully subscribed to list notifications or if the connection has been broken. This would allow you to communicate the connection to the user through the UI.
78
78
79
-
The list subscription API, exposes two additional callbacks which you can implement to respond to the subscription status. The following code illustrates the case, where the component will be notified when the subscription has been established and when it was disconnected.
79
+
The list subscription API, exposes two additional callbacks that you can implement to respond to the subscription status. The following code illustrates the case, where the component will be notified when the subscription has been established and when it was disconnected.
80
80
81
81
```typescript
82
82
privatecreateListSubscription(): void {
@@ -108,7 +108,7 @@ The method for the `callbacks.disconnect` callback passes as an argument the rea
108
108
109
109
- all SharePoint Framework components can use the list subscription capabilities
110
110
- you can subscribe to events from libraries (but not lists)
111
-
- there is a few seconds delay between the change and the notification being received by the component
111
+
- there's a few seconds delay between the change and the notification being received by the component
112
112
- components can subscribe to changes in multiple Document Libraries
113
113
- the change notification doesn't pass any information about the added or changed document. To see what has changed, use the SharePoint REST API or Microsoft Graph
0 commit comments