benefits? • Flexibility. • Decoupled architecture. • (easily) Upgradable/changeable front-end. • Dedicated/Focused teams. • Happy front-end developers. 9 @brian_ward But we already have a theme-layer in Drupal? What are the
RESTful Web Services RESTful Web Services exposes entities and other resources as a RESTful web API. Required 11 @brian_ward So what do we get out of the box?
Serialization Serialization module provides a service for (de)serializing data to/from formats such as JSON and XML Required 12 @brian_ward So what do we get out of the box?
16 @brian_ward 3 ways to create a REST API with D8 Using the core RestResources Using View REST exports Create custom REST resources Option #1 Option #2 Option #3
Using the core REST resources /node/{node} /entity/block/{block} /comment/{comment} /entity/comment_type/{comment_type} @brian_ward 17 Option #1 Using the core REST resources
Pros & Cons @brian_ward 20 ✓ Straight out of the box. ✓ Requires almost no setup. ✓ No custom code necessary. - Exposes system information. - Absolutely no flexibility. - Lacks ability to version. - Unable to limit output. Using the core REST resources
23 @brian_ward Pros & Cons ✓ Straight out of the box. ✓ Familiar to developers. ✓ Manageable within the UI. - Returns data with incorrect types. - More flexibility, but still limited in various areas. - Authentication issues. Using views REST export
Creating custom REST resources Option #3 (recommended) Being object-oriented by nature, D8 allows us to extend the base ResourceBase class and create our own custom resources. This would be my recommendation. 24 @brian_ward Creating custom rest resources
HATEOAS API Theory HATEOAS is a constraint of the REST application architecture. In a nutshell, it is providing information on how to navigate the site's REST resources dynamically by including hypermedia links with the responses. 30 @brian_ward HATEOAS
Content negotiation 32 @brian_ward HATEOAS ?_format=json Basically, this is the mechanism for determining what content-type the data will be returned in. Ideally, we would want to use an “accept” header.
Introducing Vue.js Vue.js is a MVVM JavaScript library for building modern web interfaces. It provides data-reactive components with a simple and flexible API. @brian_ward 41 Introducing Vue.js
Top trending JS framework on Github. @brian_ward Introducing Vue.js 42 First stable version released earlier this month. Evan You is also a core developer on the MeteorJS project & previously a Google employee. Has awesome documentation.
ViewModel 45 @brian_ward new Vue({ /* options */ }) • An object that syncs the Model and the View. • Every Vue instance is a ViewModel. Introducing Vue.js
Model new Vue({ data: {} }) An object that is used as data inside a Vue instance will become reactive (Vue instances that are observing our objects will be notified of the changes). @brian_ward 46 Introducing Vue.js
var MyComponent = Vue.extend({}) Components 47 @brian_ward Components are simply a convenient way to structure and organise our applications. Optional Introducing Vue.js
Browserify & Vueify require('./app.vue') 48 @brian_ward Browserify lets you require('modules') in the browser by bundling up all of your dependencies. Optional Introducing Vue.js
this.$http.get(url, callback) VueResource Using the official Vue-Resource plugin, we can request and store our Drupal content as data objects. Recommended 49 @brian_ward Introducing Vue.js
Great, let’s see that in action! Firstly we will need to create our package.json, HTML & bootstrap JS files. From there we’ll load in our components and interact with our API. @brian_ward 53 Introducing Vue.js
And that’s it. By using Drupal 8 and Vue.js we’re able to create a beautiful, maintainable and de-coupled application. https://github.com/briward/examples 63 @brian_ward