WordPress Rest API response

You might be able to output your headers with the response. Then just kill the request with exit();.

The default is usually to return a value and let the process encode and output for you.


Based on http://v2.wp-api.org/extending/adding/

function my_awesome_func( $data ) {
    header("Content-Type: text/plain");
    print_r( array('foo'=>'bar'));
    exit();
}

add_action( 'rest_api_init', function () {
    register_rest_route( 'myplugin/v1', '/test/', array(
        'methods' => 'GET',
        'callback' => 'my_awesome_func',
    ) );
} );