Drupal 8: Using web services using curl

Enable web service in Drupal 8.

Go to Manage->Extend page and enable the following modules:

  • HAL
  • HTTP Basic Authentication
  • RESTful Web Services
  • Serialization

Create an article

# Change the followings to match your Drupal setup:
#  URL->http://qn/d8/
#  Username and password->admin:x
CONTENT='{
            "_links":{
                "type":{"href":"http://qn/d8/rest/type/node/article"}
              },
 
              "title":[{"value":"My first page2"}],
              "body":[{"value":"This is the body content of my page"}]
          }'
curl --user admin:x --header 'Content-type: application/hal+json' --request POST  http://qn/d8/entity/node --data-binary "${CONTENT}"

Retrieve an article

# Change the following to match your Drupal setup:
#  URL->http://qn/d8/
#  Username and password->admin:x
#  Node ID->node/1
curl --user admin:x --header 'Accept: application/hal+json' --request GET http://qn/d8/node/1?_format=hal_json

Reference: