I'm doing some basic API testing and notice that restricting my new route to GET doesn't work. POST requests also go though using Postman. (PUT, PATCH, DELETE do not however, displaying a "no matching route/method" error):

function displayDummyData() {
  return 'dummy data'; // responds 'dummy data' on POST request

function checkIfAnyone() {
  return true;

function registerDummyRoute() {
  register_rest_route('wp/v2', 'tut', [
    'methods' => 'GET',
    'callback' => 'displayDummyData',
    'permission_callback' => 'checkIfAnyone'
add_action('rest_api_init', 'registerDummyRoute');

How can I restrict this route to only GET requests?

  • I copied your exact code and when I sent a POST request and received the error "No route was found matching the URL and request method". – Jacob Peattie Jul 19 '19 at 1:03
  • Also, you should not be using wp/v2 as your namespace. That's reserved for the core APIs and using it defeats the entire purpose of using namespaces. – Jacob Peattie Jul 19 '19 at 1:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.