restful application with drupal 8
TRANSCRIPT
![Page 1: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/1.jpg)
RESTful application with Drupal 8Concept / Overview / Demonstration / Happyness
![Page 2: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/2.jpg)
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
![Page 3: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/3.jpg)
Introduction
Technical Director at Esokia
10 years of experience in PHP
7 years of experience in Drupal
![Page 4: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/4.jpg)
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
![Page 5: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/5.jpg)
Drupal now
Drupal 8 released on November, 2015 (approx.)
Big architectural changes
Built with
![Page 6: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/6.jpg)
About the sessionA 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.
![Page 7: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/7.jpg)
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.
![Page 8: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/8.jpg)
RESTful?REpresentational
State
Transfert
An application that implements the REST architectural style is called a RESTful application
![Page 9: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/9.jpg)
REST PrincipleCommunicate over HTTP protocol using HTTP verbs that web browsers use between client and server
GET
PUT
DELETE
POST
PATCH
etc
![Page 10: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/10.jpg)
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
![Page 11: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/11.jpg)
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).
![Page 12: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/12.jpg)
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.
![Page 13: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/13.jpg)
GET
For reading content entities.Read-only method.
Considered as a safe method.
Results are automatically cached.
![Page 14: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/14.jpg)
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.
![Page 15: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/15.jpg)
PATCH
For updading content entities.When PATCHing resources, only send the changes.
Considered as an unsafe method.
Need a CSRF Token.
![Page 16: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/16.jpg)
DELETE
For deleting content entities.Content-type header not necessary (no request body).
Considered as an unsafe method.
Need a CSRF Token.
![Page 17: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/17.jpg)
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)
REST UI (a “Nice To Have”)
![Page 18: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/18.jpg)
Core module to enable
![Page 19: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/19.jpg)
REST UI interface
![Page 20: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/20.jpg)
List of permissions for using REST
![Page 21: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/21.jpg)
Basic example in action
![Page 22: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/22.jpg)
Little demonstration?
![Page 23: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/23.jpg)
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.
![Page 24: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/24.jpg)
JQuery exampleJQuery 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
![Page 25: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/25.jpg)
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
![Page 26: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/26.jpg)
RequirementsLAMP Stack for the backend
Linux
Apache
MySQL
PHP
![Page 27: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/27.jpg)
RequirementsMEAN Stack for the frontend
MongoDB
ExpressJS
AngularJS
NodeJS
![Page 28: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/28.jpg)
RequirementsRESTful Web Services
Views
Field UI (nice to have)
REST UI (nice to have)Drupal 8 installation
![Page 29: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/29.jpg)
Live conding?
![Page 30: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/30.jpg)
LAMP Stack
Be efficient: Google Cloud + Bitnami is a good combo! :-D
Good combo is a pre-installed Drupal’s LAMP Stack.
![Page 31: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/31.jpg)
MEAN Stack
Be efficient: Google Cloud + Bitnami is a good combo! :-D (really!)
![Page 32: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/32.jpg)
NodeJS Locally
![Page 33: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/33.jpg)
ExpressJS Locally
![Page 34: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/34.jpg)
ExpressJS locally
![Page 35: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/35.jpg)
Let’s try
Drupal:● Content type● Views● Permissions
Remember to configure the view for the REST Export!
![Page 36: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/36.jpg)
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
![Page 37: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/37.jpg)
Drupal <-> NodeJS
Need to install NPM Request module
Load it in your Express App
Interact with Drupal!
![Page 38: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/38.jpg)
Questions?
![Page 39: RESTful application with Drupal 8](https://reader030.vdocuments.us/reader030/viewer/2022020301/58ed2fdf1a28ab62688b45ab/html5/thumbnails/39.jpg)
Thank you!