Headless Drupal

The Gizra way

//DavidHernández

  • Preparing a Restful endpoint in the backend
  • Consuming the API on the frontend
  • Real time notifications

Grab the code:

https://github.com/RoySegall/drupal-elm-starter

Backend

RESTful is a way to communicate between a provider (Drupal) and a consumer (JS application) using several fundamentals operations:

GET, POST, DELETE, PATCH/PUT

The Restful module

  • Maintained by amitaibu and e0ipso
  • Avoid drupalisms
  • Supports versioning
  • Supports multiple formats
  • Build for developers

Authentication

There are couple of ways to authenticate using the RESTful module but let’s talk about something a bit more “global” - access token.

Access token is a string contains odd characters and numbers which represent the user in the system. We will pass the access token in each request.

$http.get('http://localhost/drupal/api/login-token', {
  headers: {
    'Authorization': 'Basic ' + Base64.encode(username + ':' + password)
  }
})

Coding time

Creating content (POST)

Frontend

How do you call an Elm developer?

ELMO

  • Elm is a purely functional language
  • For creating web browser based graphical UIs
  • It’s compiled into javascript
  • Focused into usability, performance and robustness
  • Statically typed

On the business side:

  • Clients pay for the features, not the bugs.
  • Compilation errors VS Runtime exceptions

On the dev side:

  • Easy testing
  • Quick development
  • It’s super fun

The Elm Architecture

  • A model to represent our data
  • A view for representing the model
  • Messages for the operations we can do with our model
  • An update function to modify our data

Elm 101

Types

Union types

Dealing with Union types

Records and functions

Coding time

again!

Real time notifications

There are two ways of communication

One way direction (HTTP)

Bidirectional (phone call)

Websockets

Websocket is a communication protocol which connect a server and a client and allow to stream data regularly.

Pusher

Pusher is a service that allows us to keep track of the active users and send them notifications in real time.

Demo

Want to see more?

https://github.com/Gizra/drupal-elm-starter

Find me around

Headless Drupal

By david_hernandez

Headless Drupal

Headless Drupal: The Gizra way. Session for DrupalCamp Spain 2017

  • 1,121
Loading comments...

More from david_hernandez