Skip to content

Instantly share code, notes, and snippets.

@jmichaelward
Created July 8, 2020 14:37
Show Gist options
  • Save jmichaelward/7f0397ba2d43cebd76dd109f3108d30d to your computer and use it in GitHub Desktop.
Save jmichaelward/7f0397ba2d43cebd76dd109f3108d30d to your computer and use it in GitHub Desktop.
/* global wp, myPlugin */
const {
apiFetch
} = wp;
const postMyData = () => {
apiFetch.use( apiFetch.createNonceMiddleware( myPlugin.nonce ) );
apiFetch(
{
path: 'myPlugin/v1/myEndpoint',
method: 'POST',
data: { myDataPoint: 'somestring' }
}
)
.then( result => {
// Do something with the result
} )
.error( error => {
// Do something with the error
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment