How to install package @wordpress/api-fetch? How to install package @wordpress/api-fetch?
npm install @wordpress/api-fetch --save
How to use package @wordpress/api-fetch? How to use package @wordpress/api-fetch?
Examples Examples
Example of GET request in @wordpress/api-fetch Example of GET request in @wordpress/api-fetch
import apiFetch from '@wordpress/api-fetch'; // Request with GET method. apiFetch( { path: '/wp/v2/posts' } ).then( posts => { // console.log( posts ); } );
Example of POST request in @wordpress/api-fetch Example of POST request in @wordpress/api-fetch
import apiFetch from '@wordpress/api-fetch'; // Request with POST method. apiFetch( { path: '/wp/v2/posts/1', method: 'POST', data: { title: 'My New Post' }, } ).then( res => { console.log( res ); } );