How to Get Data via Wordpress API

Asked

Viewed 41 times

0

I wanted to start learning React.js and for this I decided to make a theme written in React for my wordpress, using the 'new' functionality WP API. How do I get access to the API from my computer? I know I have to authorize the call to the API, but I don’t know how to do it. See how I’m trying to get the information:

componentDidMount() {
let dataURL = "http://meusite.com/wp-json/wp/v2/books?_embed";
fetch(dataURL)
  .then(res => res.json())
  .then(res => {
    this.setState({
      movies: res
    })
  })
}

I get error 425 (visible from Chrome devtools) when calling the URL that returns Json.

How can I allow access?

1 answer

1


Read routes will always be public in wordpress unless you apply a filter to protect them.. Read the list of posts for example, whether for custom post type or not you don’t need to authenticate..

the routes to add new content in the database, you need authentication..

Using Oauth2 you will have a lot of work to understand if you are not familiar with it.. You can choose to use JWT to do this authentication.. Whatever authentication mode you use, you will need to install the plugin..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.