Get featured image and additional posts thumbnail Wordpress REST API

I want to use the REST API of wordpress to build a new version of a custom theme. I'm able to get the json response of a particular category, but I need to find a way to obtain also the featured image or the second post thumbnail registered using a plugin, so I can use them in the layout. Is this possible without using a plugin?

here is the code I'm using for testing:

script
(function($){
  $(document).ready(function(){

    $.getJSON('https://localhost/wordpress/wp-json/wp/v2/posts?category_name=portfolioper_page=50_embed', function(response){
      console.log(response);
      $.each(response, function(i){
        console.log(response[i]._embedded['wp:featuredmedia'][0].source_url);
      });
    });

  });
}(jQuery));
/script

the last part of the console log will not work but the [0].source_url is the info I need for each JSON post provided.

Topic rest-api post-thumbnails Wordpress

Category Web


(function($){
  $(document).ready(function(){
    var items = [];
    $.getJSON('https://localhost/wordpress/wp-json/wp/v2/posts?category_name=portfolio&per_page=50&_embed', function(response){
      console.log(response);
      $.each(response, function(key,val){
        //console.log(val._embedded['wp:featuredmedia'][0].source_url);
        items.push(''+''+
                     '');
      });
    });

  });
}(jQuery));

//use variable array to push data

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.