rest_no_route, no route was found matching the URL and request method WordPress

The issue:

This is the issue we got when we were working with WordPress REST APIs. To generate WordPress token we were using JWT authentication plugin. When we tried to get the token using this URL (/wp-json/jwt-auth/v1/token) we got into this issue and the error message was:

{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}   

The reason:

According to the JWT authentication plugin we setup everything and activated the plugin. Following is our .htaccess file content:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</IfModule>
# END WordPress

We also set the config correctly like below:

define("JWT_AUTH_SECRET_KEY", "<somekey>");
define("JWT_AUTH_CORS_ENABLE", true);

But we are calling an WordPress REST endpoint using GET method for which the GET method was not available. For example if we try to call this endpoint (/wp-json/jwt-auth/v1/token) with GET method we will get the above error. For this endpoint(/wp-json/jwt-auth/v1/token) only POST method is allowed.

The solution:

In our case we had use POST method to solve this issue.

Endpoint                   | HTTP Verb
/wp-json/jwt-auth/v1/token | POST

There are many other cases where WordPress REST API call will show this error.