Skip to content

Commit d8590e6

Browse files
Merge pull request SharePoint#6534 from andrewconnell/spfx-doc-refresh
Refresh & fixedup markdown for Connected APIs section …
2 parents c1d2d0d + 2a0409a commit d8590e6

9 files changed

+130
-129
lines changed

docs/spfx/connect-to-anonymous-apis.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Connect to anonymous APIs
33
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
55
ms.prod: sharepoint
66
localization_priority: Priority
77
---
@@ -28,7 +28,9 @@ this.context.httpClient
2828
});
2929
```
3030

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:
3234

3335
```typescript
3436
this.context.httpClient
@@ -48,12 +50,12 @@ this.context.httpClient
4850

4951
### Considerations for using the HttpClient
5052

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.
5254

5355
#### Authentication cookies not included
5456

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.
5658

5759
#### Part of the SharePoint Framework
5860

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.

docs/spfx/connect-to-sharepoint.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
title: Connect to SharePoint APIs
33
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
55
ms.prod: sharepoint
66
localization_priority: Priority
77
---
88

99
# Connect to SharePoint APIs
1010

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.
1212

1313
## Connect to SharePoint API using the SPHttpClient
1414

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:
1616

1717
```typescript
1818
this.context.spHttpClient
@@ -25,7 +25,7 @@ this.context.spHttpClient
2525
});
2626
```
2727

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:
2929

3030
```typescript
3131
this.context.spHttpClient
@@ -46,11 +46,11 @@ this.context.spHttpClient
4646

4747
### Considerations for using the SPHttpClient
4848

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.
5050

5151
#### OData v4.0
5252

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:
5454

5555
```typescript
5656
this.context.spHttpClient
@@ -72,15 +72,15 @@ this.context.spHttpClient
7272

7373
#### Authentication cookies
7474

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.
7676

7777
#### Part of the SharePoint Framework
7878

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.
8080

8181
#### Raw REST queries are error-prone
8282

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.
8484

8585
## Connect to SharePoint using PnPjs
8686

@@ -97,26 +97,26 @@ sp.web
9797

9898
[!INCLUDE [pnp-js](../../includes/snippets/open-source/pnp-js.md)]
9999

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 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 strongly typed lowering the risk of runtime errors.
101101

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/).
103103

104104
### Considerations for using PnPjs
105105

106106
When deciding whether you should use PnPjs or not, following are a few considerations that you should take into account.
107107

108108
#### Raw REST queries are error prone
109109

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.
111111

112112
#### Open-source project
113113

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.
115115

116116
#### Additional dependency
117117

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.
119119

120120
#### Additional payload
121121

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.

docs/spfx/subscribe-to-list-notifications.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
---
22
title: Subscribe to list notifications
33
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
55
ms.prod: sharepoint
66
localization_priority: Normal
77
---
88

99
# Subscribe to list notifications
1010

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.
1212

1313
## Prerequisites
1414

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:
1616

17-
```sh
17+
```console
1818
npm install @microsoft/sp-list-subscription --save --save-exact
1919
```
2020

2121
## Get notified of changes to documents stored in a SharePoint Document Library
2222

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.
2424

2525
Following, is an example of a list subscription for a Document Library located in the current site:
2626

@@ -72,11 +72,11 @@ this._listSubscriptionFactory.createSubscription({
7272
});
7373
```
7474

75-
### Get notified when the subscription has been established or cancelled
75+
### Get notified when the subscription has been established or canceled
7676

7777
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.
7878

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.
8080

8181
```typescript
8282
private createListSubscription(): void {
@@ -108,7 +108,7 @@ The method for the `callbacks.disconnect` callback passes as an argument the rea
108108

109109
- all SharePoint Framework components can use the list subscription capabilities
110110
- 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
112112
- components can subscribe to changes in multiple Document Libraries
113113
- 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
114114

0 commit comments

Comments
 (0)