Getting error {"message":"No route found for \u0022GET \/standortimporter\/region_node_rest_resource\u0022"} custom rest POST I am creating custom rest resource using this code:

&lt;?php

    /**
     * Provides a resource to get view modes by entity and bundle.
     *
     * @RestResource(
     *   id = "region_node_rest_resource",
     *   label = @Translation("Region node rest resource"),
     *   
     *   uri_paths = {
     *     "canonical" = "/standortimporter/region_node_rest_resource"
     *   }
     * )
     */

 namespace Drupal\standortimporter\Plugin\rest\resource;


use Drupal\Core\Session\AccountProxyInterface;
use Drupal\node\Entity\Node;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Psr\Log\LoggerInterface;


    class regionNodeRestResource extends ResourceBase {


      public function post() {

              $node = "hello here";

      return new ResourceResponse($node);
      }

    }


And getting this error:


  {"message":"No route found for \u0022GET
  /standortimporter/region_node_rest_resource\u0022"}
To create a custom rest resource:


Enable rest module: drush en rest -y
Create the plugin like the following YOURMODULENAME/src/Plugin/rest/resource/RegionNodeRestResource.php:




namespace Drupal\YOURMODULENAME\Plugin\rest\resource;

use Drupal\rest\ModifiedResourceResponse;
use Drupal\rest\Plugin\ResourceBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

/**
 * Provides a resource to get view modes by entity and bundle.
 *
 * @RestResource(
 *   id = "region_node_rest_resource",
 *   label = @Translation("Region node rest resource"),
 *   uri_paths = {
 *     "create" = "/standortimporter/region-node-rest-resource"
 *   }
 * )
 */
class RegionNodeRestResource extends ResourceBase {

  /**
   * A current user instance.
   *
   * @var \Drupal\Core\Session\AccountProxyInterface
   */
  protected $currentUser;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
    $instance->currentUser = $container->get('current_user');
    return $instance;
  }

    /**
     * Responds to POST requests.
     *
     * @param string $payload
     *
     * @return \Drupal\rest\ModifiedResourceResponse
     *   The HTTP response object.
     *
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
     *   Throws exception expected.
     */
    public function post($payload) {

        // You must to implement the logic of your REST Resource here.
        // Use current user after pass authentication to validate access.
        if (!$this->currentUser->hasPermission('access content')) {
            throw new AccessDeniedHttpException();
        }

      $payload = ["hello here"];
        return new ModifiedResourceResponse($payload, 200);
    }

}




You should enable your resource using restui:
go to admin/config/services/rest you can see your endpoint and enable it.



And configure it like the following:

 4. To test you should use rest client app like Postman like:


For more informations read Custom REST Resources page.