Drupal 8 RESTfull config and get json

# Oficial documentation: https://www.drupal.org/documentation/modules/rest
# API: https://www.drupal.org/developing/api/8/rest
# Howto video: http://lin-clark.com/blog/2014/01/22/setting-up-rest-drupal-8/

# Modules
rest
serialization
HAL

# use-case: get json node data 
# https://www.drupal.org/documentation/modules/rest/get
#
# enable modules: rest, serialization and hal

drush en rest serialization hal

# After enable rest setup permissions for GET POST PUT DELETE admin/people/permissions#module-rest
# get entity:node info without authentication (give anonymous user access)

drush role-add-perm anonymous 'restful get entity:node'

# change rest.settings.yml to add json content type response 
# other option is RestUI module

drush cget rest.settings resources.'entity:node'.GET.supported_formats

# output
'rest.settings:resources.entity:node.GET.supported_formats':
  - hal_json

# # edit (add '- json')

drush cedit rest.settings resources.'entity:node'.GET.supported_formats

#edit output
resources:
  entity:node:
    GET:
      supported_formats:
      - hal_json
      - json
# save and exit
:wq
# rebuild cache

drush cr 

# test it

curl -X GET http://example.loc/node/1?_format=json
Free Tags: