Create endpoint

Last Updated: August 23, 2021

This is a very simple endpoint you can create with WordPress. You can add simple function.php function


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

function my_awesome_func( $data ) {
    
    $array = array(
        2 => array("Afghanistan",32,13),
        4 => array("Albania",32,12)
    );

   
    return json_encode($array);
}