title: wp rest api custom end point with post request
body: <p>i have a question concerning wp rest api custom endpoints
  The idea is i am trying to update database on my local server with data from database on remote site.the data is for a settings page</p>
  
  <p>I have succeeded in developing custom end points with GET  methods successfully and i have also succeeded in getting data from database to the get end point.</p>
  
  <p>My question is with the post request. How do i develop the callback function to receive data from remote site and update local database.</p>
  
  <p>Below is my code</p>
  
  <pre><code>function register_custom_route(){
  
      register_rest_route( 'silentblast-dashboard/v1', '/getsetting/(?P&lt;id&gt;\d+)', array(
  
     array(
  
     'methods' =&gt; 'GET',
      'callback' =&gt; 'retrieve_settings_data',
  
  ),
  
  array(
      'methods' =&gt; 'POST',
      'callback' =&gt; 'update_settings_data',
  
  )
  ));
  
  }
  
  function retrieve_settings_data($data){
  
  $out = get_option( 'buddysettings');
  
  return $out;
  
  
      }
  
  function update_settings_data( $posts ){
  
  }
  </code></pre>
  
  <p>Now secondly, i tried to add this to the retrieve_settings_data() function.</p>
  
  <pre><code>$url(remote url) = 'http://websiteproject.ca/blastbuilder/demo/wp-json/silentblast-dashboard/v1/getsetting/';
  
  $response =  wp_remote_get( $url );
  
  $posts = wp_remote_retrieve_body( $response );
  
  $posts = json_decode($posts);
  
  $posts = (array) $posts;
  
  $out = update_option( 'buddy_settings', $posts );
  
  $outi = get_option( 'buddy_settings' );
  
           return $outi ;
  </code></pre>
  
  <p>and it worked to update the local database with data from remote database but it updates only after i refresh the link localhost/wordpress/wp-json/silentblast-dashboard/v1/getsetting/ on the browser which is quite funny to me. This means if i change settings on spage. the remote database gets updated and posts its data to its endpoint  remotesite.com/wp-json/silentblast-dashboard/v1/getsetting/ now the code actually gets the setting data from the remote custom route and updates the local database but i can only see the updates in the browser after reloading the custom route for my local site.</p>