How to get featured image in WP rest api

I use blow code for get last products from wp-json rest api

// Get posts via REST API.
function get_posts_via_rest() {
    $allposts = "http://wordpress.stackexchange.com/";
    $response = wp_remote_get( 'https://mysite .com/product/wp-json/wp/v2/product?per_page=4' );
    if ( is_wp_error( $response ) ) {
        return;
    }
    $posts = json_decode( wp_remote_retrieve_body( $response ) );
    if ( empty( $posts ) ) {
        return;
    }
    if ( ! empty( $posts ) ) {
        foreach ( $posts as $post ) {
            $allposts .= '<div class="jl_list_post_wrapper">
  <a href="http://wordpress.stackexchange.com/" . esc_url( $post->link ) . "http://wordpress.stackexchange.com/" class="jl_small_format feature-image-link image_post featured-thumbnail">
  <img src="https://wordpress.stackexchange.com/". esc_html( $post->featured_image_src) ."http://wordpress.stackexchange.com/" class="attachment-disto_small_feature size-disto_small_feature wp-post-image"> <div class="background_over_image"></div>
  </a>
  <div class="item-details">
  <h3 class="feature-post-title"><a href="http://wordpress.stackexchange.com/" . esc_url( $post->link ) . "http://wordpress.stackexchange.com/">' . esc_html( $post->title->rendered ) . '</a></h3>
  <span class="post-meta meta-main-img auto_image_with_date">  <span class="post-date"><i class="fa fa-shopping-cart"></i> in stock</span></span> </div>
</div>';
        }
        return $allposts;
    }
}

And also user blow code for generate featured image in api

function post_featured_image_json( $data, $post, $context ) {
  $featured_image_id = $data->data('featured_media'); // get featured image id
  $featured_image_url = wp_get_attachment_image_src( $featured_image_id, 'original' ); // get url of the original size

  if( $featured_image_url ) {
    $data->data('featured_image_url') = $featured_image_url(0);
  }

  return $data;
}
add_filter( 'rest_prepare_post', 'post_featured_image_json', 10, 3 );

But this is not working in my website.
Do you have any idea to get thumbnail product image?

And how to generate (in stock) / (out of stock) in api to show to other site?