@wordpress/api-fetch 6.26.0 → 6.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +17 -3
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -14,15 +14,29 @@ _This package assumes that your code will run in an **ES2015+** environment. If
|
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
|
+
### GET
|
|
17
18
|
```js
|
|
18
19
|
import apiFetch from '@wordpress/api-fetch';
|
|
19
20
|
|
|
20
|
-
// GET
|
|
21
21
|
apiFetch( { path: '/wp/v2/posts' } ).then( ( posts ) => {
|
|
22
22
|
console.log( posts );
|
|
23
23
|
} );
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### GET with Query Args
|
|
27
|
+
```js
|
|
28
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
29
|
+
import { addQueryArgs } from '@wordpress/url';
|
|
30
|
+
|
|
31
|
+
const queryParams = { include: [1,2,3] }; // Return posts with ID = 1,2,3.
|
|
24
32
|
|
|
25
|
-
|
|
33
|
+
apiFetch( { path: addQueryArgs( '/wp/v2/posts', queryParams } ).then( ( posts ) => {
|
|
34
|
+
console.log( posts );
|
|
35
|
+
} );
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### POST
|
|
39
|
+
```js
|
|
26
40
|
apiFetch( {
|
|
27
41
|
path: '/wp/v2/posts/1',
|
|
28
42
|
method: 'POST',
|
|
@@ -52,7 +66,7 @@ Unlike `fetch`, the `Promise` return value of `apiFetch` will resolve to the par
|
|
|
52
66
|
|
|
53
67
|
#### `data` (`object`)
|
|
54
68
|
|
|
55
|
-
Shorthand to be used in place of `body`, accepts an object value to be stringified to JSON.
|
|
69
|
+
Sent on `POST` or `PUT` requests only. Shorthand to be used in place of `body`, accepts an object value to be stringified to JSON.
|
|
56
70
|
|
|
57
71
|
### Aborting a request
|
|
58
72
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/api-fetch",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.27.0",
|
|
4
4
|
"description": "Utility to make WordPress REST API requests.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"types": "build-types",
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@babel/runtime": "^7.16.0",
|
|
31
|
-
"@wordpress/i18n": "^4.
|
|
32
|
-
"@wordpress/url": "^3.
|
|
31
|
+
"@wordpress/i18n": "^4.30.0",
|
|
32
|
+
"@wordpress/url": "^3.31.0"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "d5c28a67b11e91e3e4b8e90346bfcb90909364d6"
|
|
38
38
|
}
|