How to create a user with REST in Drupal 8

This functionality is introduced in Drupal 8.3-x-dev

Drupal 8.3-x-dev is out and it comes packed with improvements to the REST module. It's now possible to create new users using REST.

First you will have to setup your REST resources. Make sure you enabled all modules:

Enable REST modules
Enable REST modules

I use the REST UI module and I recommend using it yourself because it's very handy. You don't have to edit the .yml files to enable your resources, instead you can do it with a UI.

Before this call will work you need to make sure you enable the resource for user registration.

Rest UI enable user registration resource
Enable the user registration resource using the REST UI module

The final step is enabling the permissions on this resource:

Rest UI permissions
Set permissions so anonymous users can create an account using the REST call

Now you can register a user with REST. This is an example to do it from an Angular app:

  /*
   * Register new User.
   */
  register: function (mail, password) {

    var defer = $q.defer();

    $http({
      method: 'POST',
      url: config.endpoint + '/user/register',
      dataType: 'json',
      data: {
        'name': {
          'value': mail,
        },
        'mail': {
          'value': mail,
        },
        'pass': {
          'value': password,
        }
      },
    })
      .success(function (data, status, headers, config) {
        defer.resolve(data);
      })
      .error(function (data, status, headers, config) {
        defer.reject(data);
      });

    return defer.promise;
  }

Now you are all set, enjoy!

Drupal

Meer leesvoer

I have been working on a Drupal 8 multisite and at some point I had to set up a new site in the structure. The...
Drupal
In this blog post you will learn how to add a theme field preprocess function in your theme.
Theming
In this blog post I show you how to login and logout from a Drupal 8 Back-end from an Ionic app
Drupal
It's quite easy to create a node with REST in Drupal 8, in this blog post I'll show you how to do it.
Drupal