A RESTful entity web API for Drupal 8

klausi's picture

tl;dr: klausi will help to work on a Drupal 8 core rest.module (name is work in progress) that exposes entities as RESTful web service resources.

I'm happy to announce that I will join the WSCCI initiative to help develop web service interfaces in Drupal 8. Big thanks to my team at epiqo for sponsoring and making time for me to work on this, as well as Acquia for providing a crucial financial part to make this happen.

Goal: You may know modules like Services or RESTWS, we want something similar for Drupal 8 core. It should be possible to simply enable a web API that automatically exposes any entity type via a RESTful interface. That means that we can easily apply CRUD operations (Create, Read, Update and Delete) to entities remotely. The use cases are for example native mobile applications that interact with a Drupal site, third party services that can consume Drupal resources in a standard format, mass migration of legacy data, deployment of staging content ... and a lot more. The key feature is a standard-compliant, machine-readable interface that opens Drupal up for integration with any external system.

Time frame: I will be working on this for at least two days per week aiming to finish this until Drupal core feature freeze on December 1st. I will need your help to get this done, so don't hesitate to jump in and take part in the issue queue. We are short on time and I will specifically push for a minimum viable product, so don't expect any features more than basic CRUD for entities.

Technical details: I'm planning to work on connecting the new routing system with the new serialization system that uses the new entity property API system. JSON-LD will be the default serialization format, leaving the possibility to add others with contributed modules. An incoming request will be mapped to the intended entity/resource type, the request body will be de-serialized from the specified format, the operation will be applied from the HTTP request method. An entity/resource will then be created/read/updated/deleted and a possible response will be prepared for the specified format.

As RESTWS maintainer I'm of course biased with how that module works, so you can expect a similar solution. There is some ugliness in it due to the limitations of Drupal 7, I'm aware of that and will address it with sweet Symfony sauce and other newly available core tools (routing, plugins, PSR-0, request objects, upcoming serialization + JSON-LD, yadda yadda ...).

First task: Implement the Delete operation on entities. This does not require any serialization, so we can focus on routing and how to handle the request flow with "resource controllers" or whatever the responsible parts will be called.

There is also an initial discussion on groups.drupal.org for more details. I will follow-up with more core issues soon. Happy hacking!