@wordpress/api-fetch

Advertisement

How to install package @wordpress/api-fetch? How to install package @wordpress/api-fetch?

npm install @wordpress/api-fetch --save

Top ↑

How to use package @wordpress/api-fetch? How to use package @wordpress/api-fetch?

Top ↑

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 );
} );

Top ↑

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 );
} );

Leave a Reply