2

I am trying to set up the REST module for Drupal8.2.7. Install went through without problems.

I tried to follow this documentation page https://www.drupal.org/docs/8/api/restful-web-services-api/restful-web-services-api-overview to set up a simple resource for getting nodes.

I followed the descriptions for 'Drupal 8.2 & Later: ' and created this yml file in the this folder \Drupal\rest\RestResourceConfigInterface

id: entity.node
plugin_id: 'entity:node'
granularity: method
configuration:
  GET:
    supported_formats:
      - json
    supported_auth:
      - basic_auth
      - cookie

Once that was done I cleared the cache and expected to be able to get node 1 as json using this url:

/node/1?_format=json

However, all I receive is: {"message":"Not acceptable format: json"}

What am I missing here?

Update: I went to here /admin/config/development/configuration/single/export and exported entity.node

uuid: d44c745b-d69b-4893-8f31-b65d0fe80bf0
langcode: en
status: true
dependencies:
  module:
    - basic_auth
    - hal
    - node
  _core:
    default_config_hash: t_jfECmZhJqBOJuSOFn87EOi_TWi-_fRYTuJgd19vgg
  id: entity.node
    plugin_id: 'entity:node'
    granularity: resource
  configuration:
    methods:
      - GET
      - POST
      - PATCH
      - DELETE
    formats:
      - json 
      - hal_json
    authentication:
      - basic_auth
    GET:
      supported_formats:
        - json
        - xml
      supported_auth:
        - basic_auth
        - cookie
    POST:
      supported_formats:
        - hal_json
        - json
        - xml
      supported_auth:
        - basic_auth
        - cookie
   DELETE:
     supported_formats:
       - hal_json
       - json
       - xml
  supported_auth:
    - basic_auth
    - cookie
  PATCH:
    supported_formats:
      - hal_json
      - json
      - xml
    supported_auth:
      - basic_auth
      - cookie

However, trying to get my node via the mentioned url '/node/1?_format=json' still returns {"message":"Not acceptable format: json"}

4

\Drupal\rest\RestResourceConfigInterface is a namespace not a directory structure.

Configuration files need to be imported into the active configuration which is stored in the database.

In the case of a single config file:

  1. Go to the page /admin/config/development/configuration/single/import

  2. Under "Configuration type" select "REST resource configuration" In the box

  3. At "Paste your configuration here" paste your REST YAML configuration

Configuration can be exported and imported using the config directory, as specified in settings.php with the line $config_directories['sync'] = 'sites/default/config';.

To export the current active configuration to files in the sync directory use the drush command: drush config-export

To import configuration from files in the sync directory and overwrite your current active configuration, go to the page /admin/config/development/configuration.

Another option is to use the REST UI module to configure your REST services.

  • 1
    Thanks a lot for your detailed answer. Much appreciated. I do not fully understand how to enable 'JSON' for 'nodes' though. I will update the questions with my exported yml files – Uwe Apr 3 '17 at 3:57
  • 1
    Just to clarify: I went to the URL you described, I exported the existing yml and made sure that ' json' was listed as supported format for 'nodes'. – Uwe Apr 3 '17 at 4:08
  • 1
    What happens when you follow the 3 step instructions I suggested to import the YAML into configuration? This will make sure it has been imported correctly. – imclean Apr 3 '17 at 4:39
  • 1
    @Uwe Exporting the configuration is just a third of the process; you still need to import it back in the configuration. – kiamlaluno Apr 3 '17 at 5:26
  • 1
    I have the same problem using the REST UI module. That was the reason for me to try it the other way in the first place – Uwe Apr 3 '17 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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