Custom REST Resource POST problem I want to POST json data to a custom REST resource. I tested with postman and Insomnia but i get the message as if would've done a GET request and returns the get functions result. The GET function works fine btw.

In the logs it says "Switched from post to get".

I just want to return the data the user passes. This is the code of my custom REST resource:

&lt;?php
namespace Drupal\foolzz_rest_api\Plugin\rest\resource;


use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;

/**
 * Provides User Profile REST Resource
 *
 * @RestResource(
 *   id = "profile_resource",
 *   label = @Translation("Profile resource"),
 *   uri_paths = {
 *     "canonical" = "/foolzz_rest_api/profile/{uid}"
 *   }
 * )
 */
class ProfileResource extends ResourceBase
{
    /**
     * Responds to entity GET requests.
     * @return \Drupal\rest\ResourceResponse
     */
    public function get($uid = NULL)
    {
        $query = \Drupal::database()-&gt;select('foolzz_users_profile', 'data');
        $query-&gt;fields('data', array('fk_users_uid','status','displayname','birthdate','biography','gender','realname'));
        $query-&gt;condition('data.fk_users_uid', $uid);

        $profile = $query-&gt;execute()-&gt;fetchAssoc();

        $response = ['profile' =&gt; $profile
        ];

        $build = array(
            '#cache' =&gt; array(
                'max-age' =&gt; 0,
            ),
        );

        return (new ResourceResponse($response))-&gt;addCacheableDependency($build);
    }

    /**
     * Responds to POST requests.
     * @return \Drupal\rest\ResourceResponse
     * Returns a list of bundles for specified entity.
     *
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
     *   Throws exception expected.
     */
    public function post(array $data = []) {

        $response = array(
            "data" =&gt; $data,
        );

        $build = array(
            '#cache' =&gt; array(
                'max-age' =&gt; 0,
            ),
        );

        return (new ResourceResponse($response))-&gt;addCacheableDependency($build);
    }
}
Looks like you've stumbled across the same stumbling block as I have a couple of times. Try with this piece of code - note the create entry after canonical: 

 *   uri_paths = {
 *     "canonical" = "/foolzz_rest_api/profile/{uid}",
 *     "https://www.drupal.org/link-relations/create" = "/foolzz_rest_api/profile/{uid}"
 *   }
 * )


Read more at: 
https://www.drupal.org/node/2811757
and
https://www.drupal.org/docs/8/api/restful-web-services-api/restful-web-services-api-overview

Oh and for the post request, I'd use ModifiedResourceResponse instead of fiddling with cache headers by hand (I learned about the existence of that from Drupal Core's EntityResource)