Post request to custom end point

2019-09-06 09:32发布

问题:

I wish to make a post request to a remote site but so that it updates remote site with data from database. I succeeded in getting the data using get request from database of current site but am unable to create a callback function for the post request. This is my code

function register_custom_route(){

register_rest_route( 'silentblast-dashboard/v1', '/getsetting/(?P<id>\d+)', array(
        array(
            'methods' => 'GET',
            'callback' => 'retrieve_settings_data',
            ),

        array(
            'methods' => 'POST',
            'callback' => 'update_settings_data',
            )
            ));
}

function retrieve_settings_data(){

$out = get_option( 'buddysettings');

return $out;

}

function update_settings_data( $posts ){

//How to build this code to make post requests to remote site

}