SlideShare a Scribd company logo
Drupal, JSON:API, and
Cheap Canned Beer
Paul McKibben
Drupalcamp Atlanta
September 13, 2019
About me...
● Working with Drupal since 2007.
● Run my own consultancy.
● Implemented sites of all sizes on
Drupal 5, 6, 7, and 8.
● I like cheap canned beer.
paul@turbojettech.com
Twitter: @paulmckibben
www.turbojettech.com
The backstory...
Image from https://www.facebook.com/BeerCanMuseumandHallofFame - The Beer Can Museum in East Taunton, MA
● 2013: On a whim, I bought the domain
cheapcannedbeer.com
● 2017: Slowly started building site in my
(ahem) spare time.
● November 2017: integrated with Alexa
using custom Drupal module.
● September 2019: no more custom
module! Now using core JSON:API.
What am I showing you today?
Alexa, ask Cheap Canned
Beer to play Trivia.
Here is your
question:...
CheapCannedBeer.com
JSON:API
AWS Lambda:
Trivia storage service
AWS S3:
Stored trivia
questions
AWS Lambda:
Cheap Canned Beer
skill handler
What is JSON:API?
JSON
Javascript Object Notation
API
Application Programming
Interface
JSON:API
A specification for building APIs
using JSON to create, read,
update, and delete content.
JSON:API? Tell me more...
● Enables anything to use
Drupal content.
● Drupal’s strength: content
structure/architecture.
● Alternatives: GraphQL,
core REST, custom HTTP
Dries compared REST, GraphQL, and JSON:API -
https://dri.es/headless-cms-rest-vs-jsonapi-vs-graphql
What does a JSON:API document look like?
{
"links": {
"self": "http://example.com/articles",
"next": "http://example.com/articles?page[offset]=2",
"last": "http://example.com/articles?page[offset]=10"
},
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON:API paints my bikeshed!"
},
"relationships": {
"author": {
"links": {
"self": "http://example.com/articles/1/relationships/author",
This is a partial example. See the full example on the homepage of https://jsonapi.org.
Setting up JSON:API on Drupal
● In core - Drupal 8.7.x and beyond. Just enable the module!
● Defaults to read-only (HTTP GET).
● Consider jsonapi_extras module to refine exposed entities.
● Consider entity_access_audit module to review exposed
entities and fields.
● If enabling PUT, POST, and DELETE, be especially careful.
JSON:API - a Drupal example
JSON:API - structured data is important
Parts of a JSON:API document
data: the document’s primary data, e.g. the properties/fields of a Drupal node
Parts of a JSON:API document
data : attributes represent information about the primary object
Parts of a JSON:API document
data : relationships represent objects related to the primary object
Parts of a JSON:API document
included represent related objects loaded as part of the same request
JSON:API request for trivia questions
● To get all nodes of a certain type, HTTP GET this URL:
http(s)://(domain)/jsonapi/node/(type)
● For Cheap Canned Beer trivia question nodes:
https://www.cheapcannedbeer.com/jsonapi/node/trivia_question
● Problem: “reference” fields (paragraphs, files) refer to other
objects!
● They need to be “included,” or we only see their IDs.
Example: paragraph fields without “include”
JSON:API “include” parameter
● Use “include” to load referenced paragraphs and images in
the same request.
● Specify the fields that reference other objects you need to
load.
● For Cheap Canned Beer trivia question nodes:
https://www.cheapcannedbeer.com/jsonapi/node/trivia_question?
include=field_choices,field_answer_image
Example: included paragraph
We need these!
Next: Pulling and Parsing JSON:API data
Alexa, ask Cheap Canned
Beer to play Trivia.
Here is your
question:...
CheapCannedBeer.com
JSON:API
AWS Lambda:
Trivia storage service
AWS S3:
Stored trivia
questions
AWS Lambda:
Cheap Canned Beer
skill handler
AWS Lambda Function
● “Serverless”
● Stateless
● Cheap/free way to run a
small task.
● Easy to integrate with
other AWS services. Image:
https://gideonpyzer.dev/blog/2017/02/05/create-a
n-aws-lambda-function-in-javascript/
Trivia Storage Service
JSON:API
AWS Lambda:
Trivia Storage Service
AWS S3:
Stored trivia
questions CheapCannedBeer.com
● Triggered by CloudWatch every 3
hours.
● Uses JSON:API to read trivia
questions from Drupal.
● Parses out the important bits;
removes HTML tags.
● Stores result in S3 as JSON object.
● Written in Javascript (Node.js).
After Trivia Storage Service parses/stores data:
Next: Skill Handler uses S3 for trivia questions
Alexa, ask Cheap Canned
Beer to play Trivia.
Here is your
question:...
CheapCannedBeer.com
JSON:API
AWS Lambda:
Trivia storage service
AWS S3:
Stored trivia
questions
AWS Lambda:
Cheap Canned Beer
skill handler
Alexa Skill Handler
● Reads JSON object from S3.
● Uses Alexa Skills Kit to define
handlers for Cheap Canned Beer
intents and slots.
● Also written in Javascript (Node.js).
AWS Lambda:
Cheap Canned Beer
skill handler
AWS S3:
Stored trivia
questions
Terminology for Alexa Skills
● Invocation name
The name users call out to activate your skill.
● Interaction model
The words and phrases users can say to use your
skill. These are modeled as Intents.
● Intent
Something a user wants to do with your skill.
● Slot
A variable that gets filled in the course of an
interaction, e.g. the answer to a trivia question.
Invocation name
“Alexa, ask
Cheap Canned Beer to
Play Trivia.”
Intent
The PlayTrivia Dialog Model
Play trivia
Dialog.ElicitSlot
{Answer} slot
Dialog.ElicitSlot
{Answer}
No
Here’s your question...
[the correct answer is…]
Do you want to play again?
Thanks for playing!{PlayAgain} slot
Cheap Canned Beer on Alexa!
The full picture, one more time...
Alexa, ask Cheap Canned
Beer to play Trivia.
Here is your
question:...
CheapCannedBeer.com
JSON:API
AWS Lambda:
Trivia storage service
AWS S3:
Stored trivia
questions
AWS Lambda:
Cheap Canned Beer
skill handler
Take-aways
● Drupal is well-positioned: a key open source content
manager for applications of all kinds.
● JSON:API in core makes it possible to write
applications that interface with Drupal content.
● Good content structure is important! Don’t put
everything in the body field.
Questions?
Contact me:
Paul McKibben
Email: paul@turbojettech.com
Twitter: @paulmckibben
Thank you!
www.turbojettech.com

More Related Content

Similar to Drupal, JSON:API, and Cheap Canned Beer - Drupalcamp Atlanta 2019

Introduction to Graph Databases
Introduction to Graph DatabasesIntroduction to Graph Databases
Introduction to Graph Databases
Paolo Pareti
 
ArangoDB
ArangoDBArangoDB
Create responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJSCreate responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJS
Hannes Hapke
 
RESTful APIs: Promises & lies
RESTful APIs: Promises & liesRESTful APIs: Promises & lies
RESTful APIs: Promises & lies
Tareque Hossain
 
Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)
Julian Hyde
 
Not Your Father’s Web App: The Cloud-Native Architecture of images.nasa.gov
Not Your Father’s Web App: The Cloud-Native Architecture of images.nasa.govNot Your Father’s Web App: The Cloud-Native Architecture of images.nasa.gov
Not Your Father’s Web App: The Cloud-Native Architecture of images.nasa.gov
Chris Shenton
 
No sql database and python -- Presentation done at Python Developer's meetup ...
No sql database and python -- Presentation done at Python Developer's meetup ...No sql database and python -- Presentation done at Python Developer's meetup ...
No sql database and python -- Presentation done at Python Developer's meetup ...
Roshan Bhandari
 
Introduction to Riak and Ripple (KC.rb)
Introduction to Riak and Ripple (KC.rb)Introduction to Riak and Ripple (KC.rb)
Introduction to Riak and Ripple (KC.rb)
Sean Cribbs
 
Sinatra Rack And Middleware
Sinatra Rack And MiddlewareSinatra Rack And Middleware
Sinatra Rack And Middleware
Ben Schwarz
 
DBAs vs Developers: JSON in SQL Server
DBAs vs Developers: JSON in SQL ServerDBAs vs Developers: JSON in SQL Server
DBAs vs Developers: JSON in SQL Server
Bert Wagner
 
API Documentation presentation to East Bay STC Chapter
API Documentation presentation to East Bay STC ChapterAPI Documentation presentation to East Bay STC Chapter
API Documentation presentation to East Bay STC Chapter
Tom Johnson
 
API Documentation -- Presentation to East Bay STC Chapter
API Documentation -- Presentation to East Bay STC ChapterAPI Documentation -- Presentation to East Bay STC Chapter
API Documentation -- Presentation to East Bay STC Chapter
Tom Johnson
 
Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)
Matteo Collina
 
Battle of NoSQL stars: Amazon's SDB vs MongoDB vs CouchDB vs RavenDB
Battle of NoSQL stars: Amazon's SDB vs MongoDB vs CouchDB vs RavenDBBattle of NoSQL stars: Amazon's SDB vs MongoDB vs CouchDB vs RavenDB
Battle of NoSQL stars: Amazon's SDB vs MongoDB vs CouchDB vs RavenDB
Jesse Wolgamott
 
Bada familiar foundations
Bada  familiar foundationsBada  familiar foundations
Bada familiar foundations
jlansdell
 
Dead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPIDead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPI
Chris Tankersley
 
Enter the app era with ruby on rails
Enter the app era with ruby on railsEnter the app era with ruby on rails
Enter the app era with ruby on rails
Matteo Collina
 
Back-end (Flask_AWS)
Back-end (Flask_AWS)Back-end (Flask_AWS)
Back-end (Flask_AWS)
GDSC UofT Mississauga
 
API Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIsAPI Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIs
Tom Johnson
 
Getting into ember.js
Getting into ember.jsGetting into ember.js
Getting into ember.js
reybango
 

Similar to Drupal, JSON:API, and Cheap Canned Beer - Drupalcamp Atlanta 2019 (20)

Introduction to Graph Databases
Introduction to Graph DatabasesIntroduction to Graph Databases
Introduction to Graph Databases
 
ArangoDB
ArangoDBArangoDB
ArangoDB
 
Create responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJSCreate responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJS
 
RESTful APIs: Promises & lies
RESTful APIs: Promises & liesRESTful APIs: Promises & lies
RESTful APIs: Promises & lies
 
Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)
 
Not Your Father’s Web App: The Cloud-Native Architecture of images.nasa.gov
Not Your Father’s Web App: The Cloud-Native Architecture of images.nasa.govNot Your Father’s Web App: The Cloud-Native Architecture of images.nasa.gov
Not Your Father’s Web App: The Cloud-Native Architecture of images.nasa.gov
 
No sql database and python -- Presentation done at Python Developer's meetup ...
No sql database and python -- Presentation done at Python Developer's meetup ...No sql database and python -- Presentation done at Python Developer's meetup ...
No sql database and python -- Presentation done at Python Developer's meetup ...
 
Introduction to Riak and Ripple (KC.rb)
Introduction to Riak and Ripple (KC.rb)Introduction to Riak and Ripple (KC.rb)
Introduction to Riak and Ripple (KC.rb)
 
Sinatra Rack And Middleware
Sinatra Rack And MiddlewareSinatra Rack And Middleware
Sinatra Rack And Middleware
 
DBAs vs Developers: JSON in SQL Server
DBAs vs Developers: JSON in SQL ServerDBAs vs Developers: JSON in SQL Server
DBAs vs Developers: JSON in SQL Server
 
API Documentation presentation to East Bay STC Chapter
API Documentation presentation to East Bay STC ChapterAPI Documentation presentation to East Bay STC Chapter
API Documentation presentation to East Bay STC Chapter
 
API Documentation -- Presentation to East Bay STC Chapter
API Documentation -- Presentation to East Bay STC ChapterAPI Documentation -- Presentation to East Bay STC Chapter
API Documentation -- Presentation to East Bay STC Chapter
 
Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)
 
Battle of NoSQL stars: Amazon's SDB vs MongoDB vs CouchDB vs RavenDB
Battle of NoSQL stars: Amazon's SDB vs MongoDB vs CouchDB vs RavenDBBattle of NoSQL stars: Amazon's SDB vs MongoDB vs CouchDB vs RavenDB
Battle of NoSQL stars: Amazon's SDB vs MongoDB vs CouchDB vs RavenDB
 
Bada familiar foundations
Bada  familiar foundationsBada  familiar foundations
Bada familiar foundations
 
Dead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPIDead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPI
 
Enter the app era with ruby on rails
Enter the app era with ruby on railsEnter the app era with ruby on rails
Enter the app era with ruby on rails
 
Back-end (Flask_AWS)
Back-end (Flask_AWS)Back-end (Flask_AWS)
Back-end (Flask_AWS)
 
API Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIsAPI Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIs
 
Getting into ember.js
Getting into ember.jsGetting into ember.js
Getting into ember.js
 

Recently uploaded

Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
Enterprise Knowledge
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
christinelarrosa
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during MigrationMust Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
Mydbops
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 

Recently uploaded (20)

Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during MigrationMust Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 

Drupal, JSON:API, and Cheap Canned Beer - Drupalcamp Atlanta 2019

  • 1. Drupal, JSON:API, and Cheap Canned Beer Paul McKibben Drupalcamp Atlanta September 13, 2019
  • 2. About me... ● Working with Drupal since 2007. ● Run my own consultancy. ● Implemented sites of all sizes on Drupal 5, 6, 7, and 8. ● I like cheap canned beer. paul@turbojettech.com Twitter: @paulmckibben www.turbojettech.com
  • 3. The backstory... Image from https://www.facebook.com/BeerCanMuseumandHallofFame - The Beer Can Museum in East Taunton, MA ● 2013: On a whim, I bought the domain cheapcannedbeer.com ● 2017: Slowly started building site in my (ahem) spare time. ● November 2017: integrated with Alexa using custom Drupal module. ● September 2019: no more custom module! Now using core JSON:API.
  • 4. What am I showing you today? Alexa, ask Cheap Canned Beer to play Trivia. Here is your question:... CheapCannedBeer.com JSON:API AWS Lambda: Trivia storage service AWS S3: Stored trivia questions AWS Lambda: Cheap Canned Beer skill handler
  • 5. What is JSON:API? JSON Javascript Object Notation API Application Programming Interface JSON:API A specification for building APIs using JSON to create, read, update, and delete content.
  • 6. JSON:API? Tell me more... ● Enables anything to use Drupal content. ● Drupal’s strength: content structure/architecture. ● Alternatives: GraphQL, core REST, custom HTTP Dries compared REST, GraphQL, and JSON:API - https://dri.es/headless-cms-rest-vs-jsonapi-vs-graphql
  • 7. What does a JSON:API document look like? { "links": { "self": "http://example.com/articles", "next": "http://example.com/articles?page[offset]=2", "last": "http://example.com/articles?page[offset]=10" }, "data": [{ "type": "articles", "id": "1", "attributes": { "title": "JSON:API paints my bikeshed!" }, "relationships": { "author": { "links": { "self": "http://example.com/articles/1/relationships/author", This is a partial example. See the full example on the homepage of https://jsonapi.org.
  • 8. Setting up JSON:API on Drupal ● In core - Drupal 8.7.x and beyond. Just enable the module! ● Defaults to read-only (HTTP GET). ● Consider jsonapi_extras module to refine exposed entities. ● Consider entity_access_audit module to review exposed entities and fields. ● If enabling PUT, POST, and DELETE, be especially careful.
  • 9. JSON:API - a Drupal example
  • 10. JSON:API - structured data is important
  • 11. Parts of a JSON:API document data: the document’s primary data, e.g. the properties/fields of a Drupal node
  • 12. Parts of a JSON:API document data : attributes represent information about the primary object
  • 13. Parts of a JSON:API document data : relationships represent objects related to the primary object
  • 14. Parts of a JSON:API document included represent related objects loaded as part of the same request
  • 15. JSON:API request for trivia questions ● To get all nodes of a certain type, HTTP GET this URL: http(s)://(domain)/jsonapi/node/(type) ● For Cheap Canned Beer trivia question nodes: https://www.cheapcannedbeer.com/jsonapi/node/trivia_question ● Problem: “reference” fields (paragraphs, files) refer to other objects! ● They need to be “included,” or we only see their IDs.
  • 16. Example: paragraph fields without “include”
  • 17. JSON:API “include” parameter ● Use “include” to load referenced paragraphs and images in the same request. ● Specify the fields that reference other objects you need to load. ● For Cheap Canned Beer trivia question nodes: https://www.cheapcannedbeer.com/jsonapi/node/trivia_question? include=field_choices,field_answer_image
  • 19. Next: Pulling and Parsing JSON:API data Alexa, ask Cheap Canned Beer to play Trivia. Here is your question:... CheapCannedBeer.com JSON:API AWS Lambda: Trivia storage service AWS S3: Stored trivia questions AWS Lambda: Cheap Canned Beer skill handler
  • 20. AWS Lambda Function ● “Serverless” ● Stateless ● Cheap/free way to run a small task. ● Easy to integrate with other AWS services. Image: https://gideonpyzer.dev/blog/2017/02/05/create-a n-aws-lambda-function-in-javascript/
  • 21. Trivia Storage Service JSON:API AWS Lambda: Trivia Storage Service AWS S3: Stored trivia questions CheapCannedBeer.com ● Triggered by CloudWatch every 3 hours. ● Uses JSON:API to read trivia questions from Drupal. ● Parses out the important bits; removes HTML tags. ● Stores result in S3 as JSON object. ● Written in Javascript (Node.js).
  • 22. After Trivia Storage Service parses/stores data:
  • 23. Next: Skill Handler uses S3 for trivia questions Alexa, ask Cheap Canned Beer to play Trivia. Here is your question:... CheapCannedBeer.com JSON:API AWS Lambda: Trivia storage service AWS S3: Stored trivia questions AWS Lambda: Cheap Canned Beer skill handler
  • 24. Alexa Skill Handler ● Reads JSON object from S3. ● Uses Alexa Skills Kit to define handlers for Cheap Canned Beer intents and slots. ● Also written in Javascript (Node.js). AWS Lambda: Cheap Canned Beer skill handler AWS S3: Stored trivia questions
  • 25. Terminology for Alexa Skills ● Invocation name The name users call out to activate your skill. ● Interaction model The words and phrases users can say to use your skill. These are modeled as Intents. ● Intent Something a user wants to do with your skill. ● Slot A variable that gets filled in the course of an interaction, e.g. the answer to a trivia question. Invocation name “Alexa, ask Cheap Canned Beer to Play Trivia.” Intent
  • 26. The PlayTrivia Dialog Model Play trivia Dialog.ElicitSlot {Answer} slot Dialog.ElicitSlot {Answer} No Here’s your question... [the correct answer is…] Do you want to play again? Thanks for playing!{PlayAgain} slot
  • 27. Cheap Canned Beer on Alexa!
  • 28. The full picture, one more time... Alexa, ask Cheap Canned Beer to play Trivia. Here is your question:... CheapCannedBeer.com JSON:API AWS Lambda: Trivia storage service AWS S3: Stored trivia questions AWS Lambda: Cheap Canned Beer skill handler
  • 29. Take-aways ● Drupal is well-positioned: a key open source content manager for applications of all kinds. ● JSON:API in core makes it possible to write applications that interface with Drupal content. ● Good content structure is important! Don’t put everything in the body field.
  • 31. Contact me: Paul McKibben Email: paul@turbojettech.com Twitter: @paulmckibben Thank you! www.turbojettech.com