How to use the @wordpress/api-fetch.setFetchHandler function in @wordpress/api-fetch

To help you get started, we’ve selected a few @wordpress/api-fetch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / wordpress__api-fetch / wordpress__api-fetch-tests.ts View on Github external
);
    const response = await apiFetch({ parse: false });
    if (response.ok) {
        console.log(await response.json());
    }
}

const x: Middleware = async (undefined, next) => {
    const x = await next({});
    return next({});
};

apiFetch.use(apiFetch.fetchAllMiddleware);
apiFetch.use(apiFetch.createRootURLMiddleware('https://foo.bar/wp-json'));

apiFetch.setFetchHandler(options => {
    const { url, path, data, method } = options;

    return fetch(url || path || '', {
        method,
        body: JSON.stringify(data),
    });
});
github wordpress-mobile / gutenberg-mobile / src / api-fetch-setup.js View on Github external
export default () => {
	apiFetch.setFetchHandler( ( options ) => fetchHandler( options ) );
};