Wordpress REST API Endpoint
<p>I am writing an Angular WP theme and i'm trying to reduce the number of HTTP requests on the post page. </p>

<p>On the post page I want to list all the different taxonomies, recent posts, get the featured image and a few other things. I can do this all with individual requests with the REST API v2 plugin but that's a lot of requests.</p>

<p>I was hoping to create an endpoint for my theme, parse the post slug and get it all back in one request but I can't seem to figure it out. </p>

<p>I was thinking of using query string to get the slug. Here's what I have been using to test it out:</p>

<pre><code>function app_get_post($data) {
    global $wp_query;

    return [
        'test' =&gt; $data,
        'vars' =&gt; $wp_query-&gt;query_vars
    ];
}

add_action( 'rest_api_init', function () {
    register_rest_route( 'app/v1', '/post', [
        'methods' =&gt; 'GET',
        'callback' =&gt; 'app_get_post',
    ] );
} );
</code></pre>

<p>Here's what it produces:</p>

<pre><code>{
test: { },
vars: [ ]
}
</code></pre>

<p>I did try adding the query var with a <code>query_vars</code> hook but it didn't work either. </p>

<p>Any suggestions? Am I going about this the right way?</p>