Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/post documentation for apiFetch #19759

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/api-fetch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,22 @@ _This package assumes that your code will run in an **ES2015+** environment. If
```js
import apiFetch from '@wordpress/api-fetch';

// GET
apiFetch( { path: '/wp/v2/posts' } ).then( posts => {
console.log( posts );
} );

// POST
apiFetch( {
path: '/wp/v2/posts/1',
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify( { title: 'New Post Title' } ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure you can drop the headers and the body here and replace with just:

Suggested change
body: JSON.stringify( { title: 'New Post Title' } ),
data: { title: 'New Post Title' },

Copy link
Contributor Author

@momotofu momotofu Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point. I was able verified that. Let's go with the terser example.

} ).then( res => {
console.log( res );
} );
```

### Options
Expand Down