How to use the @wordpress/api-fetch.createNonceMiddleware 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 front / gutenberg-js / src / js / scripts / api-fetch.js View on Github external
import apiFetch from '@wordpress/api-fetch';

// Middleware
apiFetch.use(apiFetch.createNonceMiddleware(window.wpApiSettings.nonce));
apiFetch.use(apiFetch.createRootURLMiddleware(window.wpApiSettings.root));
github WordPress / health-check / src / javascript / site-health / Stores / Tests / Tests.js View on Github external
import { registerStore } from '@wordpress/data';
import apiFetch from "@wordpress/api-fetch";

apiFetch.use( apiFetch.createNonceMiddleware( SiteHealth.nonce.api_nonce ) );

const SiteHealth_DefaultState_Tests = {
	tests: [],
	isLoading: true,
	results: {
		good: [],
		recommended: [],
		critical: [],
	},
};

const actions = {
	setLoading( loading ) {
		return {
			type: 'SET_LOADING',
			loading
github WordPress / health-check / src / javascript / troubleshooting-mode / Stores / Notices / Notices.js View on Github external
import { registerStore } from '@wordpress/data';
import apiFetch from "@wordpress/api-fetch";

apiFetch.use( apiFetch.createNonceMiddleware( HealthCheckTS.api_nonce ) );

const SiteHealth_TroubleshootingMode_DefaultState_Notices = {
	notices: [],
};

const actions = {
	setNotices( notices ) {
		return {
			type: 'SET_NOTICES',
			notices,
		};
	},

	fetchFromAPI( path ) {
		return {
			type: 'FETCH_FROM_API',