WordPress.org

Make WordPress Core

Opened 12 months ago

Closed 12 months ago

Last modified 12 months ago

#46160 closed defect (bug) (worksforme)

No route was found matching the URL and request method

Reported by: RogueWebDesign Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: REST API Keywords: reporter-feedback
Focuses: Cc:
PR Number:

Description

Since WordPress version 5.0.3, it seems the "register_rest_route" function is no longer working as expected.

All custom endpoints are now returning:

code: "rest_no_route",
message: "No route was found matching the URL and request method",

Previously, our endpoints were working without issue. Here is an example of our rest_api_ini action:

<?php
function register_our_custom_api_routes() {
    register_rest_route( 'custom-namespace/v1', '/endpointtest', array(
            'methods'  => 'POST',
            'callback' => 'our_custom_callback_function',
        )
    );

    function our_custom_callback_function() {
        /* Do Things */
    }

}

add_action( 'rest_api_init', 'register_our_custom_api_routes' );

We have tested this on multiple installs with all plugins disabled and using the Twenty Nineteen theme. The namespace shows up with all the endpoints at:

{testdomain}/wp-json/custom-namespace/v1

However, trying to access {testdomain}/wp-json/custom-namespace/v1/endpointtest returns the error "rest_no_route".

Note: the above example has been adjusted for security purposes.

The issue is occurring across all WordPress sites we have checked.

Thanks :)

Change History (4)

#1 @TimothyBlynJacobs
12 months ago

  • Keywords reporter-feedback added; needs-patch dev-feedback removed
  • Severity changed from critical to normal

This is working fine for me.

I added the custom code to a sample plugin, and adjusted the callback to return data.

<?php
function our_custom_callback_function() {
        return array( 'test' );
}

Making a POST request, and I get the expected result.

curl -X POST http://trunk.test/wp-json/custom-namespace/v1/endpointtest
["test"]

How are you testing?

#2 @RogueWebDesign
12 months ago

  • Resolution set to worksforme
  • Status changed from new to closed

Hi Timothy,

Thanks for the quick response.

It seems to only be when trying to access the endpoint directly in a browser, in attempt to view the JSON data. I successfully made a POST request via terminal like your example.

Was there an update that prevents viewing the JSON response directly? Perhaps this was always the case.

I will have to debug further as to why a clients REST API integration stopped working. Most likely something on their side.

Cheers

#3 @desrosj
12 months ago

  • Milestone Awaiting Review deleted

Removing Awaiting Review milestone from closed tickets.

#4 @TimothyBlynJacobs
12 months ago

This is likely because the method is only set to POST, so the REST API cannot generate a GET response that you'd see in your browser. You could simulate it by using the _method query arg:

http://trunk.test/wp-json/custom-namespace/v1/endpointtest?_method=post
Note: See TracTickets for help on using tickets.