When working with RESTful Web Services, the HTTP POST method is used to create new entities. We will use the HTTP Basic Authentication to authenticate a user and create a new node.
In this recipe, we will use the exposed node endpoint to create a new piece of article content through the RESTful Web Services module. We will use the json
format. In the There's more... section, we will discuss how to use the HAL module for the hal_json
format.
You will use the Article
content type provided by the standard installation. Following the preceding recipe, Enabling RESTful interfaces, you should have the REST UI module added to your Drupal installation using Composer. This can be done with the following command:
cd /path/to/drupal8 composer require drupal/restui
In this recipe, the Drupal 8 installation is accessible through http://127.0.0.1:8888
. Use the appropriate URL for your Drupal 8 site.