When POSTing an entity using REST, you have to POST to /entity/{entity_type}
(for example /entity/node
or /entity/taxonomy_term
) in Drupal 8.0.x, 8.1.x, 8.2.x and 8.3.x. This was forgotten in https://www.drupal.org/node/2199185.
Of course, you'd expect to be able to post to /node
or /taxonomy_term
. This is now supported in Drupal 8.4.x, for all entity types that have a create
link template (for the https://www.drupal.org/link-relations/create
link relation type) in their entity type annotation.
Old code that makes requests to /entity/{entity_type}
continues to work, because a BC layer is in place: so POST /entity/taxonomy_term
requests are automatically mapped to POST /taxonomy/term
.
Note: only for the User entity type does this not yet work, due to other bugs blocking it. This will be fixed by #2851984: Add "create" link template to User entity type annotation, to allow POSTing to /user instead of /entity/user. So, for users, continue to use POST /entity/user
, for now.
How does this work on the Drupal/PHP/server side?
In other words: just like the REST module in Drupal 8.0.x, 8.1.x, 8.2.x and 8.3.x has already been using the canonical
link template of an entity type if it is specified in favor of its default (/entity/{entity_type}/{entity}
), starting in Drupal 8.4.x, it will do exactly the same for the create
link template (for the https://www.drupal.org/link-relations/create
link relation type): it will use that instead of the default (/entity/{entity_type}
).
Contributed modules that provide additional entity types
Contributed modules that provide entity types that also wish to take advantage of this merely need to specify this link template in their annotation, and it will start working, and they'll get a BC layer automatically too!
(We simply added this same link template to all of core's entity types.)