How to register a new user with REST in Drupal 8

How to register a new user with REST in Drupal 8

It's very easy to register new users using REST in Drupal 8. This functionality was introduced in Drupal 8.3.

Let's say you are building an app and you want to use Drupal as your back-end. The first thing you would need to do is enable all the required modules (/admin/modules).

REST modules
Enable the required REST modules

You will notice I use the REST UI module. By using this module we don't have to edit .yml files to enable resources, instead everything is configurable in the UI.

The next step is to enable the resource to register users (/admin/config/services/rest):

User registration resource
Enable the user registration resource

When the user registration resource is enabled we need to make sure anonymous users can create a new account (/admin/people/permissions):

Create user
Enable Access POST on User registration resource for anonymous users

For the sake of this example we make sure visitors can create an account without a verification mail (/admin/config/people/accounts):

Account registration settings
Visitors can create an account without an email verification

Now everything is setup properly, when we throw a POST call to our back-end a new user will be created:

Postman create user account
Create a user with postman with name "fons", mail "" and password "test"

And in our Drupal back-end we will see a user is successfully created:

Created user
The user we created using our POST call