Drupal 8 REST Resource POST Method

I need help implementing a custom REST API using the POST method in Drupal 8.

I have a REST resource plugin class and get () method. I can access this resource using the GET method and it works fine.

I have a post () method in the same class, but it cannot access the resource using the POST method, although when viewing through the "REST UI" module, the message "POST" is displayed.

REST UI Settings Page

But when accessed via the POST method, it is displayed after an error.

{"message":"No route found for \u0022POST \/iot\/location\/\u0022: Method Not Allowed (Allow: GET)"}

I am using the POSTMAN Chrome extension and screenshot below REST API Testing

I used the following blog to write a REST API, and my code is almost the same as the code shown in this blog post.

http://enzolutions.com/articles/2014/12/16/how-to-create-a-rest-resource-in-drupal-8/

Thanks at Advance.

+4
1

, uri_paths REST, " https://www.drupal.org/link-relations/create".

, - :

/**
 * My REST Resource
 *
 * @RestResource(
 *   id = "my_rest_resource",
 *   label = @Translation("My REST Resource"),
 *   uri_paths = {
 *     "canonical" = "/my_rest/resource"
 *   }
 * )
 */

POST /my_rest_resource. POST /my_rest/resource, :

/**
 * My REST Resource
 *
 * @RestResource(
 *   id = "my_rest_resource",
 *   label = @Translation("My REST Resource"),
 *   uri_paths = {
 *     "canonical" = "/my_rest/resource",
 *     "https://www.drupal.org/link-relations/create" = "/my_rest/resource"
 *   }
 * )
 */

https://www.drupal.org/link-relations/create. , GET , , , POST "405 ".

Drupal (https://www.drupal.org/docs/8/api/restful-web-services-api/restful-web-services-api-overview) .

0

Source: https://habr.com/ru/post/1622329/


All Articles