<?php

add_action( 'rest_api_init', function () {
  register_rest_route( 'poc', '/foo', array(
    'methods' => 'GET',
    'callback' => 'poc_endpoint',
    'permission_callback' => '__return_true',
  ) );
} );

function poc_endpoint( $request ) {
    // Output should match input get_params();
    return $request->get_params();
}

add_action( 'wp_enqueue_scripts', function () {
	wp_enqueue_script( 'wp-url' );
	wp_enqueue_script( 'wp-api-fetch' );
} );

add_action( 'wp_print_footer_scripts', function() {
?>
    <script>
        (function() {
            // addQueryArgs with param bar = boolean false
            var path = wp.url.addQueryArgs( '/poc/foo', { bar: false } );
            wp.apiFetch( { path: path } ).then( response => {
                // response.bar here is a string "false" and not boolean false
                console.log( response.bar === false );
                console.log( typeof response.bar );
                console.log( response.bar );
            } );
        })()
    </script>
<?php
} );
