Last active
April 15, 2024 10:19
-
-
Save vanaf1979/7f1db9d7f67d49a339f56d65222b941b to your computer and use it in GitHub Desktop.
Setup Axios for the WordPress Rest Api https://since1979.dev/snippet-014-setup-axios-for-the-wordpress-rest-api/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Import remote dependencies. | |
*/ | |
import Axios from 'axios'; | |
/* | |
* Create a Api object with Axios and | |
* configure it for the WordPRess Rest Api. | |
* | |
* The 'mynamespace' object is injected into the page | |
* using the WordPress wp_localize_script function. | |
*/ | |
const Api = Axios.create({ | |
baseURL: mynamespace.rootapiurl, | |
headers: { | |
'content-type': 'application/json', | |
'X-WP-Nonce': mynamespace.nonce | |
} | |
}); | |
export default Api; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment