0

I have a custom rest resource I have created within my module:

/**
 * Provides a Demo Resource
 *
 * @RestResource(
 *   id = "custom",
 *   label = @Translation("custom"),
 *   uri_paths = {
 *     "canonical" = "/rest/custom"
 *   }
 * )
 */
class custom extends ResourceBase {
public function get() {
    return new ResourceResponse("Response");
}

I have a rest.resource.custom.yml file in my module/custom/install folder to activate the end point when the module gets installed but it doesnt work:

id: module.custom
plugin_id: 'custom'
granularity: method
status: true
configuration:
  GET:
    supported_formats:
      - json
    supported_auth:
      - cookie

How do you enable rest endpoints when module is installed?

2 Answers 2

0

The error was in the .yml file with the id: attribute. Dont need to include the module name with it:

id: custom
plugin_id: 'custom'
granularity: method
status: true
configuration:
  GET:
    supported_formats:
      - json
    supported_auth:
      - cookie
0

If you enable the core Configuration Manager module you can export any or all configurations on your site. After you configure your module's REST resource, go to /admin/config/development/configuration/single/export and choose "REST resource configuration" for the configuration type, then choose "custom" (your RestResource plugin ID) for the configuration name - the export will show you the proper contents and tell you what to name your .yml file.

This is the best way to ensure that the .yml contains the exact configuration you want and that all the necessary information is present. This process would have prevented you from having the original problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.