Built with axios, this package provides a wrapper for Wordpress REST API for fetching data from wordpress hosted sites.
$ npm install wordpress-sdk --save
or if you use yarn
$ yarn add wordpress-sdk
import{wordpress}from'wordpress-sdk'// orconst{ wordpress }=require('wordpress-sdk')wordpress.initialize({// your wordpress rest api base URLurl: 'https://developer.wordpress.org/wp-json/wp/v2',})wordpress.allPosts().then(response=>{console.log(response.posts)}).catch(error=>{console.log(error.message)})Or using async await
try{const{ posts }=awaitwordpress.allPosts()console.log(posts)}catch(error){console.log(error.message)}wordpress.allCategories().then(response=>{console.log(response.categories)}).catch(error=>{console.log(error.message)})Or using async await
try{const{ categories }=awaitwordpress.allCategories()console.log(categories)}catch(error){console.log(error.message)}