title: The handler for the route is invalid - Wordpress
body: <p>I am trying to create a custom REST API endpoint in WordPress using Classes. I've also done the same the traditional way - which worked just fine. However, using classes I am getting an error <code>The handler for the route is invalid</code>.</p>
  <p>The code:</p>
  <pre><code>class CSS_Ads {
  
      var $url;
      var $endpointPrefix;
      var $endpointName;
  
      public function __construct()
      {
          add_action('rest_api_init', array( $this, 'ads_api_route' ) );
      }
  
      public function ads_api_route() {
          register_rest_route( $this-&gt;endpointPrefix, $this-&gt;endpointName,
              array(
                  'methods'  =&gt; 'GET',
                  'callback' =&gt; 'get_all_ads_api_endpoint'
              )
          );
      }
  
      public function get_all_ads_api_endpoint($params) {
          // doing my post query and stuff
      }
  
  }
  </code></pre>
  <p>Setting:</p>
  <pre><code>$ads = new CSS_Ads();
  $ads-&gt;url = get_site_url();
  $ads-&gt;endpointPrefix = 'bs/v1';
  $ads-&gt;endpointName = 'ads';
  </code></pre>
  <p>Full error:</p>
  <pre><code>{&quot;code&quot;:&quot;rest_invalid_handler&quot;,&quot;message&quot;:&quot;The handler for the route is invalid&quot;,&quot;data&quot;:{&quot;status&quot;:500}}
  </code></pre>
  <p>The query is set to -1, there is only one post on the website so it shouldn't matter.</p>