You are here

jsonapi_resources_test.routing.yml in JSON:API Resources 8

tests/modules/jsonapi_resources_test/jsonapi_resources_test.routing.yml

File

tests/modules/jsonapi_resources_test/jsonapi_resources_test.routing.yml
View source
  1. # Defines a route where a particular user's articles can be found.
  2. jsonapi_resources_test.author_content:
  3. # %jsonapi% is a placeholder for the JSON:API base path, which can be
  4. # configured in a site's services.yml file.
  5. path: '/%jsonapi%/user/{user}/content'
  6. defaults:
  7. # Every JSON:API resource route must declare a _jsonapi_resource. The
  8. # value can either be a class or a service ID. Unlike the _controller
  9. # route default, it is not possible to declare a method name to be called.
  10. _jsonapi_resource: Drupal\jsonapi_resources_test\Resource\AuthorArticles
  11. _jsonapi_resource_types: ['node--article']
  12. requirements:
  13. _permission: 'access content'
  14. _entity_access: 'user.view'
  15. # The following requirements will automatically be set for every JSON:API
  16. # resource route and cannot be overridden here.
  17. # _content_type_format: api_json
  18. # _format: api_json
  19. # _auth: all enabled authentication providers will automatically apply
  20. options:
  21. parameters:
  22. user:
  23. type: entity:user
  24. # Defines a route where a reminder can be created for a particular user.
  25. jsonapi_resources_test.add_reminder:
  26. path: '/%jsonapi%/user/{user}/reminders'
  27. # By default, JSON:API resource accept only GET requests. For other methods
  28. # this value must be declared.
  29. methods: ['POST']
  30. defaults:
  31. _jsonapi_resource: Drupal\jsonapi_resources_test\Resource\AddReminder
  32. # Every JSON:API resource must declare the resource types which can respond
  33. # with, or, in the case of POST requests, which will be considered valid.
  34. # This default is not required if the _jsonapi_resource above overrides
  35. # \Drupal\jsonapi_resources\Resource\ResourceBase::getRouteResourceTypes().
  36. _jsonapi_resource_types: ['node--reminder']
  37. requirements:
  38. _user_is_logged_in: 'TRUE'
  39. _entity_create_access: 'node:reminder'
  40. # Custom route access works the same as it does for any other route
  41. # definition.
  42. _custom_access: Drupal\jsonapi_resources_test\Resource\AddReminder::access
  43. options:
  44. parameters:
  45. user:
  46. type: entity:user
  47. # Defines a route where a site's featured content can be found.
  48. jsonapi_resources_test.featured_content:
  49. path: '/%jsonapi%/featured-content'
  50. defaults:
  51. _jsonapi_resource: Drupal\jsonapi_resources_test\Resource\FeaturedNodes
  52. requirements:
  53. # The same route requirements for any route definition may also be used
  54. # by a JSON:API resource route.
  55. _permission: 'access content'
  56. # Defines a route where a client can find information about the authenticated
  57. # user.
  58. jsonapi_resources_test.current_user:
  59. path: '/%jsonapi%/me'
  60. defaults:
  61. _jsonapi_resource: Drupal\jsonapi_resources_test\Resource\CurrentUserInfo
  62. requirements:
  63. _user_is_logged_in: 'TRUE'
  64. # Defines a route where a comment can be created on an article.
  65. jsonapi_resources_test.add_comment:
  66. path: '/%jsonapi%/comment/add'
  67. methods: ['POST']
  68. defaults:
  69. _jsonapi_resource: Drupal\jsonapi_resources_test\Resource\AddComment
  70. _jsonapi_resource_types: ['comment--comment']
  71. requirements:
  72. _entity_create_access: 'comment'