Hello!
Try to understand the drupal 8 rest api.
One of the most weird things for me - its why non-canonical url path has the key "https://www.drupal.org/link-relations/create" ?
I mean, following code looks more logical:

 *   uri_paths = {
 *     "canonical" = "/entity/{entity_type}/{entity}",
 *     "create" = "/entity/{entity_type}"
 *   }

As I see, this key used only as a string in a ResourceBase::routes() method. There are no information or functionality at https://www.drupal.org/link-relations/create.
Also, I can not find any commentaries about in in code or in documentation.
So, why?
Can somebody explain this to me, please?

Comments

vegantriathlete’s picture

@see: #2113345: Define a mechanism for custom link relationships. I think it is addressing the whole idea of that key.

vegantriathlete’s picture

@see: https://www.drupal.org/docs/8/api/restful-web-services-api/restful-web-s...

It has something to do with the difference between the path for GET | PATCH | DELETE and for POST.

vegantriathlete’s picture

I guess you are suggesting a different value for the key. Use simply "create" instead of the FQDN.

erfekkes’s picture

As I was implementing a POST method today for D9, I looked into ResourceBase.php and found that the "create" key is now supported. Happy!

public function routes() {
    $collection = new RouteCollection();

    $definition = $this->getPluginDefinition();
    $canonical_path = isset($definition['uri_paths']['canonical']) ? $definition['uri_paths']['canonical'] : '/' . strtr($this->pluginId, ':', '/') . '/{id}';
    $create_path = isset($definition['uri_paths']['create']) ? $definition['uri_paths']['create'] : '/' . strtr($this->pluginId, ':', '/');

    $route_name = strtr($this->pluginId, ':', '.');

    $methods = $this->availableMethods();
    foreach ($methods as $method) {
      $path = $method === 'POST'
        ? $create_path
        : $canonical_path;
      $route = $this->getBaseRoute($path, $method);

      // Note that '_format' and '_content_type_format' route requirements are
      // added in ResourceRoutes::getRoutesForResourceConfig().
      $collection->add("$route_name.$method", $route);
    }

    return $collection;
  }
anoopjohn’s picture

Looks like this has changed to 'create' in Drupal 9

https://www.drupal.org/project/drupal/issues/2802677