It would require making your own API endpoint and depends one what actual information you specifically require.
For example if you want the HTML that you would normally get from the functions you can do this by getting the buffer contents after calling the functions. If however you want a list of script/style urls then a better way would be to look at the various global php variables to get that information and construct your own packet of json from that to interpret on the other end.
If the former is required, here is a simple class to add in a custom API endpoint - you can then hit this using your-wordpress-url/wp-json/my_route/get_header and your-wordpress-url/wp-json/my_route/get_footer which then returns a json packet like this
{
"function": "getHeader",
"html": "<link rel=\"stylesheet\" href=\"stylesheet.css\"><etc><etc>"
}
Note : An instance of the class would typically be created on the rest_api_init
action - so Wordpress wouldn't of triggered all of its other normal actions and filters on a normal front resolve. It would be considered fairly bad practice to just get the HTML as it does below, but ultimately is possible.
Warning : The example below also has no authentication checks so would be open for all - you can add your own checks into the functions or add a permission call back
Example Class
/*-------------------*/
add_action('rest_api_init', function(){
$apiInstance = new headerfooter_api();
});
/*-------------------*/
/*-------------------*/
//MARK: Class - Header/Footer API
class headerfooter_api {
/*-------------------*/
public function __construct() {
register_rest_route('my_route', 'get_header', array(
'methods' => 'GET',
'callback' => array($this, 'getHeader'),
'permission_callback' => '__return_true'
));
register_rest_route('my_route', 'get_footer', array(
'methods' => 'GET',
'callback' => array($this, 'getFooter'),
'permission_callback' => '__return_true'
));
}
/*-------------------*/
public function getHeader($request) {
$results = ['function' => 'getHeader', 'html' => ''];
ob_start();
wp_head();
$results['html'] = ob_get_contents();
ob_end_clean();
$response = new WP_REST_Response($results);
$response->set_status(200);
return $response;
}
/*-------------------*/
public function getFooter($request) {
$results = ['function' => 'getFooter', 'html' => ''];
ob_start();
wp_footer();
$results['html'] = ob_get_contents();
ob_end_clean();
$response = new WP_REST_Response($results);
$response->set_status(200);
return $response;
}
/*-------------------*/
}