decoupled drupal 8 and iot

37
Decoupled Drupal 8 and IoT cheppers.com Miro Michalicka Drupal developer DrupalCamp London 2016

Upload: miro-michalicka

Post on 07-Apr-2017

290 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Decoupled Drupal 8 and IoT

Decoupled Drupal 8 and IoT

cheppers.com Miro MichalickaDrupal developer

DrupalCamp London 2016

Page 2: Decoupled Drupal 8 and IoT

Drupal enthusiast @Cheppers5+ years experience with web developmentBoard member of Slovak Drupal Association

whoami

Page 3: Decoupled Drupal 8 and IoT

CONTENTAPI best practises

Decoupling

Drupal 7 and Drupal 8decoupling options

Drupal 8 & IoT

Page 4: Decoupled Drupal 8 and IoT

API BEST PRACTISES

documentation

stability and consistency

flexibility

security

ease of adoption

Source: http://www.toptal.com/api-developers/5-golden-rules-for-designing-a-great-web-api

Page 5: Decoupled Drupal 8 and IoT

Decoupling

Page 6: Decoupled Drupal 8 and IoT
Page 7: Decoupled Drupal 8 and IoT

WHAT IS IT?

Page 8: Decoupled Drupal 8 and IoT

DECOUPLING

PROS

flexible front-end

lack of Drupal specialists

multivendor back-end

strengths of Drupal back-end

and back office

CONS

loose some Drupal capabilities

multiple requests for resources

growth of teams

Page 9: Decoupled Drupal 8 and IoT

DON’T MAKEFULL DECOUPLING

Page 10: Decoupled Drupal 8 and IoT
Page 11: Decoupled Drupal 8 and IoT

DRUPAL 7

RESTful Web Services

Services

RESTful

Page 12: Decoupled Drupal 8 and IoT

RESTful WEB SERVICES

PROS

partially OOP

CONS

versionable API

base for Drupal 8 REST module

Page 13: Decoupled Drupal 8 and IoT

SERVICES

PROS

active Drupal 8 branchversionable API

CONS

procedural code

most common solution

Page 14: Decoupled Drupal 8 and IoT

RESTful

PROS

OOP

versionable API

CONS

none found yet

Page 15: Decoupled Drupal 8 and IoT
Page 16: Decoupled Drupal 8 and IoT

DRUPAL 8RESTIN CORE

Page 17: Decoupled Drupal 8 and IoT

BUT…

Page 18: Decoupled Drupal 8 and IoT

DRUPAL 8

PROS

REST in core

CONS

non-versionable

~60 issues in backlog

Page 19: Decoupled Drupal 8 and IoT

DRUPAL 8

REST module

REST output from Views

Page 20: Decoupled Drupal 8 and IoT
Page 21: Decoupled Drupal 8 and IoT

RESTful FOR DRUPAL 8

Page 22: Decoupled Drupal 8 and IoT

IoT

Page 23: Decoupled Drupal 8 and IoT

INTERNET OFTHINGS

Page 24: Decoupled Drupal 8 and IoT

PICK-UPKIOSK

Page 25: Decoupled Drupal 8 and IoT

CHALLENGES

AUTHENTICATION DRUPAL REST HARDWARE

Page 26: Decoupled Drupal 8 and IoT

CHALLENGE #1

AUTHENTICATIONAUTHENTICATION

SOLUTION #1

OWN AUTHENTICATION PROVIDER

phone number and PIN

Page 27: Decoupled Drupal 8 and IoT

CHALLENGE #1

AUTHENTICATIONAUTHENTICATION

OWN AUTHENTICATION PROVIDER

<?php/** * @file * Contains \Drupal\pin_auth\Authentication\Provider\PinAuth. */namespace Drupal\pin_auth\Authentication\Provider; use Drupal\Core\Authentication\AuthenticationProviderInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; /** * HTTP Basic authentication provider. */class PinAuth implements AuthenticationProviderInterface { /** * The entity type manager. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** * Constructs a HTTP basic authentication provider object. * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity manager service. */ public function __construct(EntityTypeManagerInterface $entity_type_manager) { $this->entityTypeManager = $entity_type_manager; }

}

SOLUTION #1

Page 28: Decoupled Drupal 8 and IoT

CHALLENGE #1

AUTHENTICATIONAUTHENTICATION

public function applies(Request $request) { if (!empty($request->headers->get('pin')) && !empty($request->headers->get(‘number'))) { return TRUE; } return FALSE; } public function authenticate(Request $request) { $pin = $request->headers->get('pin'); $number = $request->headers->get('number'); $user = NULL; $user = $this->entityTypeManager->getStorage('user') ->getQuery() ->condition('field_phone_number', $number) ->condition('field_pin',$pin) ->range(0,1) ->execute(); if (!empty($user)) { return $user; } else { throw new AccessDeniedHttpException(); } }

OWN AUTHENTICATION PROVIDER

SOLUTION #1

Page 29: Decoupled Drupal 8 and IoT

CHALLENGE #2

DRUPAL REST

SOLUTION #2

OWN REST END-POINTS

Views REST outputcustom-coded end-points

Page 30: Decoupled Drupal 8 and IoT

CHALLENGE #2

Views

DRUPAL REST

OWN REST END-POINTS

SOLUTION #2

Page 31: Decoupled Drupal 8 and IoT

CHALLENGE #2

DRUPAL REST

Solve using RouteSubscriber

https://docs.google.com/presentation/d/1wN7zICkTXcQp8d8UKMQz6oaMM_C2b58AC4oN_sywRCU

ViewsOWN REST END-POINTS

SOLUTION #2

Page 32: Decoupled Drupal 8 and IoT

CHALLENGE #2

DRUPAL REST

Views UI needs some workhttps://drupal.org/node/2228141

ViewsOWN REST END-POINTS

SOLUTION #2

Page 33: Decoupled Drupal 8 and IoT

CHALLENGE #2

DRUPAL REST

use Drupal Console

OWN REST END-POINTSCustom end-points

SOLUTION #2

Page 34: Decoupled Drupal 8 and IoT

CHALLENGE #2

DRUPAL REST

enable via REST UI or rest.settings.yml

OWN REST END-POINTSCustom end-points

SOLUTION #2

Page 35: Decoupled Drupal 8 and IoT

CHALLENGE #3

easiest one

HARDWARE

HARDWARE

SOLUTION #3

Page 36: Decoupled Drupal 8 and IoT

LESSONSLEARNED

Decoupling with IoT is viable concept

Drupal 8 REST needs improvements

Page 37: Decoupled Drupal 8 and IoT

THANK YOUQUESTIONS?

Give me feedback, please.https://goo.gl/i30ywu