By mitchalbert on
hi,
Im trying to create a custom restAPI resource.
When implementing a custom GET function, i get results.
But when creating a post, i always get Method Not Allowed (Allow: GET)
Here is my post function, its simple
public function post() {
\Drupal::logger('test_module')->notice('post received');
}
any help?
Comments
Any kind of POST operation
Any kind of POST operation will show inclusion of 'entity' at the beginning of the endpoint. GET, PATCH, DELETE operations will not.
ie. If I have an entity with an id of zebra then the endpoint will show as /zebra/{zebra} for GET, PATCH, DELETE operations and /entity/zebra for the POST operation.
Most operations will likely require X-CSRF-Token header. Also make sure all operations are declared to REST with supported formats and authentication providers.
Hi,
Hi,
i faced the same problem. I solved it by copying code from the EntityResource.php file in core (/core/modules/rest/src/Plugin/rest/resource/EntityResource.php).
I added an additional canonical path in order to get POST work.