Consume WooCommerce REST API with JavaScript

0

With the WordPress REST API I can simply consume posts or any data available with JavaScript using the Fetch API or something similar (as in the example code).

As the WooCommerce REST API has authentication keys, the only way to consume something is to have the keys as parameters in the url, but I can not expose the keys in JavaScript. Is there a way to consume the API simply and securely with JavaScript?

fetch('https://example.com/wp-json/wp/v2/posts')
  .then(response => response.json())
  .then(posts => {
    posts.forEach(post => {
      console.log(post.title.rendered);
    });
  });
    
asked by anonymous 17.10.2018 / 03:51

0 answers