title: Custom route endpoint for WP-REST API gives "code": "rest_no_route", error
body: <p>I am following <a href="https://deliciousbrains.com/wp-rest-api-customizing-endpoints-adding-new-ones/" rel="noreferrer">this</a> tutorial to create custom end points to WP-API .</p>
  
  <p>I am always getting this error  on hitting <strong>/wp-json/custom-plugin/v2/get-all-post-ids/</strong> on <strong>postman</strong> to test : </p>
  
  <pre><code>{
      "code": "rest_no_route",
      "message": "No route was found matching
      the URL and request method ", 
      "data": {
          "status": 404
      }
  }
  </code></pre>
  
  <p>I have created a custom-plugin.php file in /plugins/custom-plugin/ directory .</p>
  
  <pre><code>&lt;?php
      if ( ! defined( 'ABSPATH' ) ) exit;
  
      add_action( 'rest_api_init', 'dt_register_api_hooks' );
  
      function dt_register_api_hooks() {    
  
          register_rest_route( 'custom-plugin/v2', '/get-all-post-ids/', array(
              'methods' =&gt; 'GET',
              'callback' =&gt; 'dt_get_all_post_ids',
              ) 
              );
      }
      // Return all post IDs
      function dt_get_all_post_ids() {
          if ( false === ( $all_post_ids = get_transient( 'dt_all_post_ids' ) ) ) {
              $all_post_ids = get_posts( array(
                  'numberposts' =&gt; -1,
                  'post_type'   =&gt; 'post',
                  'fields'      =&gt; 'ids',
              ) );
              // cache for 2 hours
              set_transient( 'dt_all_post_ids', $all_post_ids, 60*60*2 );
          }
          return $all_post_ids;
      }
  ?&gt;
  </code></pre>