0.1.0 • Published 3 years ago
@hamworks/wordpress-api-fetch v0.1.0
@hamworks/wordpress-api-fetch
Customized @wordpress/api-fetch
use globalThis.fetch
.
Installation
Install the module
npm install @hamworks/wordpress-api-fetch --save
Usage
import apiFetch from '@team-hamworks/wordpress-api-fetch';
// GET
let posts = await apiFetch( { path: '/wp/v2/posts' } )
console.log( posts )
// POST
let posts = await apiFetch( {
path: '/wp/v2/posts/1',
method: 'POST',
data: { title: 'New Post Title' },
} )
console.log( posts )
ES Modules
import apiFetch from 'https://cdn.pika.dev/@hamworks/wordpress-api-fetch';
const posts = await apiFetch( { path: '/wp/v2/posts' } )
console.log( posts )
Middlewares
fetchAllInParallelMiddleware
A modification of fetchAllMiddleware to perform requests in parallel.
import apiFetch from 'https://cdn.pika.dev/@hamworks/wordpress-api-fetch';
apiFetch.use( apiFetch.fetchAllInParallelMiddleware );
const posts = await apiFetch( { path: '/wp/v2/posts?per_page=-1' }, { mode: 'cors'} );
console.log(posts);