2. Introduction
Digital agency established since
2008 in Mauritius
Recognized as one of the most
expert offshore web agencies in
Drupal
More than 150 projects in Drupal
4. What is Drupal?
Free, community-built website development tool
Modular and extensible content management
Open source
Built on PHP
Created by Dries Buytaert
First release in January 2001
5. Drupal now
Drupal 8 released on November, 2015 (approx.)
Big architectural changes
Built with
6. About the
session
A little warm-up
An overview about Drupal 8 and this
new core capability to build RESTful
application. From a basic utilisation
to a more complexe use case, we
will made a global overview of
possible exploitation of Drupal 8
RESTful aspect.
7. Warm-up
Drupal 8 is the next main version of Drupal’s CMS, a quick overview and
presentation will be made for exposing the concept.
On the next topic, we will see what is REST and key concept about a RESTful
application, with basic exemple and application. A more advanced concept will
be see in the next topic, with a presentation about an utilisation of JavaScript to
use a Drupal 8 RESTful application and a more complex example with a
NodeJS / ExpressJS application.
9. REST Principle
Communicate over HTTP protocol
using HTTP verbs that web browsers
use between client and server
GET
PUT
DELETE
POST
PATCH
etc
10. REST Implementation - Two ways
GET → Retreive something
POST → Create something
DELETE → Delete something
PATCH → Update something
GET → Retrieve something
POST → Update something
DELETE → Delete something
PUT → Create something
11. What is REST in Drupal?
Make possible for other applications to read and update information on your
site via the Web.
REST is one of a number of different ways of making it available.
In contrast to other techniques such as SOAP or XML-RPC, REST encourages
developers to rely on HTTP methods (such as GET and POST) to operate on
"resources" (data managed by Drupal).
12. RESTful Web Service API
The RESTful Web Services API is new in Drupal 8.
For each REST resource, you can specify the supported verbs (i.e. GET,
POST…), and for each verb, you can specify the serialization formats &
authentication mechanisms.
In Drupal 8, there is a single central location to configure all REST resources
that a site exposes: rest.settings.yml.
A permission is generated for every resource + verb, users need this
permission to be able to interact with this REST resource.
14. POST
For creating content
entities.
Some entities need a _links entry to
the user and / or to the referenced
entity.
Never POST a UUID (or node
ID/comment ID/…) as you create a
new entity.
Considered as an unsafe method.
Need a CSRF Token.
17. Basic Example
Read and write data from your Drupal installation with a couple of modules.
Requirements:
RESTful Web Services (rest)
Serialization (serialization)
Hypertext Application Language (hal)
HTTP Basic Authentication (basic_auth)
23. JS + D8 RESTful Web Services
Can be use with every kind of entities in Drupal 8 if they are exposed for REST.
Just implement an HTTP request and let’s go.
Easy to separate client and server.
Improve the client code’s portability.
Servers can be simpler and more scalable.
24. JQuery example
JQuery already loaded in Drupal
(JQuery 1.7)
Every Drupal 8 project can be easily
RESTful with client-server separation
GET / POST /PATCH / DELETE still
available
25. Advanced Example
Building a timesheet application in Drupal 8 with a separated front-end.
What we need?
A Drupal 8 installation with RESTful Web Services API
Something funny like NodeJS
ExpressJS or a similar framework
36. Let’s try
ExpressJS
● Don’t forget to npm init before!
● And npm install express --save for dependencies
● You can add a template engine, add route with parameters, etc
37. Drupal <-> NodeJS
Need to install NPM Request
module
Load it in your Express App
Interact with Drupal!