In order to promote conventions between the documented routing systems (like entity form & view controllers) and JSON:API, it would be nice if this module allowed custom resources to be defined like so:

path: /foo/{taxonomy_term}

where {taxonomy_term} is an entity type ID and is automatically upcast by its UUID.

Comments

gabesullice created an issue. See original summary.

wim leers’s picture

See \Drupal\jsonapi\ParamConverter\EntityUuidConverter.

Once #2353611: Make it possible to link to an entity by UUID lands, this issue will be obsolete and that class can be removed.

sam711’s picture

This example is based on the jsonapi EntityUuidConverter pointed in #2 and seems to work fine with JSON:API Resources, although it has some limitations.

  path: /foo/{taxonomy_term}
  defaults:
    resource_type: 'taxonomy_term--tags'
  options:
    parameters:
      resource_type:
        type: jsonapi_resource_type
      taxonomy_term:
        type: 'entity:taxonomy_term'
lamp5’s picture

Very good example is Here

foo.rest.user.do_something:
  path: '/rest/user-foo-bar/{account}' # account contains the UUID
  defaults:
    _controller: '\Drupal\your_module\Controller\UserController::doSomething'
  methods: [POST]
  requirements:
    _permission: 'access content'
  options:
    parameters:
      account: # here is the path argument again and you define that the jsonapi converter should handle it
        type: entity:user # here you can also say entity:node or entity:comment
        converter: 'paramconverter.jsonapi.entity_uuid' # this converter needs the type parameter to guess the correct entity