How to enable data retrieval via Wordpress API

0

I wanted to start learning React.js and for this I decided to do a theme written in React for my wordpress, using the 'new' WP API functionality. How do I access the API from my computer? I know I have to authorize the API call, but I do not know how to do it. Here's 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 I call the Url returned by Json.

How can I allow access?

    
asked by anonymous 23.04.2018 / 19:31

1 answer

1

Reading routes will always be public in wordpress unless you apply a filter to protect them. Read the list of posts eg for custom post type or you do not need to authenticate.

routes to add new content to the bank, you need authentication ..

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

    
15.05.2018 / 19:48