SlideShare a Scribd company logo
1 of 39
Web APIs in Drupal 8
Larry Garfield, Senior Architect, Palantir.net
Kyle Browning, Technical Consultant, Acquia
Larry Garfield
Senior Architect, Palantir.net
Drupal Web Services Lead
Who are we?
Kyle Browning
Technical Consultant, Acquia
Services, and Drupal iOS SDK maintainer
Who are we?
What are Web Services(tm)?
The Internet (TCP/IP)
The Web (HTTP)
Web Services (non-HTML)
REST (REpresentational State Transfer)
Collection of Resources
Resource identified by URI
Resource represented in a format
Manipulate through Verbs/Methods
Known hyperlinks to other Resources
REST (Hypermedia)
So what's wrong with Drupal 7?
Drupal 7
function example_menu() {
$items['my/page'] = array(
'title' => 'My page',
'page callback' => 'my_page_function',
'access arguments' => array('access content'),
);
return $items;
}
Only map on path
Very basic access control
Drupal 7
function example_page_delivery_callback_alter(&$delivery_callback) {
if (...) {
$delivery_callback = 'example_deliver_page';
}
}
Happens after the page callback, so mostly useless.
Drupal 7
→And oh yeah, globals
▪ $_GET
▪ drupal_add_http_header()
▪ print
Drupal 7
Everything other than a full HTML page is an after-thought.
So what's better in Drupal 8?
Drupal 8
example.route:
path: /my/page
defaults:
_controller: 'DrupalexampleControllerExampleController::page'
_title: 'Example page'
requirements:
_permission: 'access_examples'
_day: 'Tuesday'
_method: 'GET'
Multiple access checks
Map on path,
Drupal 8
Arbitrary custom logic goes here
Drupal 8
Theming and page layout happen here
Drupal 8
Everything's an HTTP Response. Sometimes that's a page.
Drupal 8
→You can serve any type of response to a request
→Wire directly to the routing system.
→No duplicating routing anymore!
Drupal 8 - Serialization module
→Standard serialization/deserialization pipeline
→Built on Symfony Serializer component
$json = $this->serializer->serialize($entity, 'json');
$xml = $this->serializer->serialize($entity, 'xml');
$entity = $this->serializer->deserialize($json, 'Node' 'json');
Standard universal serialized format (for internal structure)!
Drupal 8 - REST module
→Core module for common pattern of REST usage
→~RestWS
→Uses Serialization
→Define "Resource" Plugins
▪ GET/get(), PUT/put(), DELETE/delete()
▪ Return ResourceResponse
▪ Drupal will serialize()/deserialize() for you
Drupal 8 - REST resources
class DBLogResource extends ResourceBase {
public function get($id = NULL) {
if ($id) {
$record = db_query("SELECT * FROM {watchdog} WHERE wid = :wid", [':wid' => $id])
->fetchAssoc();
if (!empty($record)) {
return new ResourceResponse($record);
}
throw new NotFoundHttpException(t('Log entry with ID @id was not found', ['@id' => $id]));
}
throw new HttpException(t('No log entry ID was provided'));
}
}
Drupal 8 - REST resources
All Content Entities are supported out-of-the-box
● Uses same URL as HTML page
● All supported formats, automatically
● Opt-in configuration
Easily add your own resources, too
Teach serializer about it (Normalizer)
Create new Resource plugin
Profit!!1!
Drupal 8 - Content Negotiation
Reverse proxies suck
+
Browsers suck even more
=
Accept-based negotiation is broken 90% of the time :-(
Drupal 8 - Content Negotiation
http://example.com/node/5?&_format=hal_json
http://example.com/node/5?&_format=xml
http://example.com/node/5?&_format=html (default)
Drupal 8
REST UI
Drupal 8
REST UI
Drupal 8 - Hypermedia Links
Coming soon!
(8.1? As soon as someone works on it.)
https://www.drupal.org/node/2113345
What does Services module do?
Drupal 8 - Services
→Provide endpoint capabilities to put your API behind a
centralized URL
→Standardize on an approach to building non-REST
APIs
→Accept Header content negotiation
→Gives us regular json response instead of hal_json
→Config entities too!
Drupal 8 - ServicesDefinition
→Defines the ‘resource’
→Protein of Services in
D8
→Route Access
→Request method
Drupal 8 - ServicesDefinition
Still respects core
Config Entities!
Lets grab a block
Create a block
Update a block
And since everything is an entity.
Drupal 8 - Views
Respects Permissions
Thank You

More Related Content

What's hot

Service Oriented Web Development with OSGi - C Ziegeler
Service Oriented Web Development with OSGi - C ZiegelerService Oriented Web Development with OSGi - C Ziegeler
Service Oriented Web Development with OSGi - C Ziegeler
mfrancis
 
Head First Zend Framework - Part 1 Project & Application
Head First Zend Framework - Part 1 Project & ApplicationHead First Zend Framework - Part 1 Project & Application
Head First Zend Framework - Part 1 Project & Application
Jace Ju
 

What's hot (20)

Whats New in the Http Service Specification - Felix Meschberger
Whats New in the Http Service Specification - Felix MeschbergerWhats New in the Http Service Specification - Felix Meschberger
Whats New in the Http Service Specification - Felix Meschberger
 
CodeIgniter 3.0
CodeIgniter 3.0CodeIgniter 3.0
CodeIgniter 3.0
 
What happens in laravel 4 bootstraping
What happens in laravel 4 bootstrapingWhat happens in laravel 4 bootstraping
What happens in laravel 4 bootstraping
 
REST API with CakePHP
REST API with CakePHPREST API with CakePHP
REST API with CakePHP
 
Code Igniter 2
Code Igniter 2Code Igniter 2
Code Igniter 2
 
Frontend Servers and NGINX: What, Where and How
Frontend Servers and NGINX: What, Where and HowFrontend Servers and NGINX: What, Where and How
Frontend Servers and NGINX: What, Where and How
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
 
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech TalkContract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
 
Service Oriented Web Development with OSGi - C Ziegeler
Service Oriented Web Development with OSGi - C ZiegelerService Oriented Web Development with OSGi - C Ziegeler
Service Oriented Web Development with OSGi - C Ziegeler
 
Diving into php
Diving into phpDiving into php
Diving into php
 
Head First Zend Framework - Part 1 Project & Application
Head First Zend Framework - Part 1 Project & ApplicationHead First Zend Framework - Part 1 Project & Application
Head First Zend Framework - Part 1 Project & Application
 
Alfresco study37 alfresco_ng2_components
Alfresco study37 alfresco_ng2_componentsAlfresco study37 alfresco_ng2_components
Alfresco study37 alfresco_ng2_components
 
Designing CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIsDesigning CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIs
 
Salesforce CLI Cheat Sheet
Salesforce CLI Cheat Sheet Salesforce CLI Cheat Sheet
Salesforce CLI Cheat Sheet
 
WebGUI Developers Workshop
WebGUI Developers WorkshopWebGUI Developers Workshop
WebGUI Developers Workshop
 
Node.js and Parse
Node.js and ParseNode.js and Parse
Node.js and Parse
 
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
 
Spring java config
Spring java configSpring java config
Spring java config
 
JWT - Sécurisez vos APIs
JWT - Sécurisez vos APIsJWT - Sécurisez vos APIs
JWT - Sécurisez vos APIs
 
the Spring 4 update
the Spring 4 updatethe Spring 4 update
the Spring 4 update
 

Viewers also liked

Viewers also liked (20)

Headless Drupal, Singapore Drupal Meetup
Headless Drupal, Singapore Drupal MeetupHeadless Drupal, Singapore Drupal Meetup
Headless Drupal, Singapore Drupal Meetup
 
Introducing Acquia Content Hub: Take Control of Your Content Chaos
Introducing Acquia Content Hub: Take Control of Your Content ChaosIntroducing Acquia Content Hub: Take Control of Your Content Chaos
Introducing Acquia Content Hub: Take Control of Your Content Chaos
 
Mb Portfolio 20091201
Mb Portfolio 20091201Mb Portfolio 20091201
Mb Portfolio 20091201
 
Use Content to Enhance Your Commerce Experience
Use Content to Enhance Your Commerce ExperienceUse Content to Enhance Your Commerce Experience
Use Content to Enhance Your Commerce Experience
 
Responsive & Ready: Why Drupal 8 is Ideal for Building Mobile-first Experienc...
Responsive & Ready: Why Drupal 8 is Ideal for Building Mobile-first Experienc...Responsive & Ready: Why Drupal 8 is Ideal for Building Mobile-first Experienc...
Responsive & Ready: Why Drupal 8 is Ideal for Building Mobile-first Experienc...
 
Entities 101: Understanding Data Structures in Drupal
Entities 101: Understanding Data Structures in DrupalEntities 101: Understanding Data Structures in Drupal
Entities 101: Understanding Data Structures in Drupal
 
Applied progressive decoupling weather.com, angular, and drupal
Applied progressive decoupling  weather.com, angular, and drupalApplied progressive decoupling  weather.com, angular, and drupal
Applied progressive decoupling weather.com, angular, and drupal
 
Build Mobile Applications with Headless Drupal 8 - DrupalConAsia 2016
Build Mobile Applications with Headless Drupal 8 - DrupalConAsia 2016Build Mobile Applications with Headless Drupal 8 - DrupalConAsia 2016
Build Mobile Applications with Headless Drupal 8 - DrupalConAsia 2016
 
What Is a Cloud-first Headless CMS
What Is a Cloud-first Headless CMSWhat Is a Cloud-first Headless CMS
What Is a Cloud-first Headless CMS
 
Going Global 101: How to Manage Your Websites Worldwide Using Drupal
Going Global 101: How to Manage Your Websites Worldwide Using DrupalGoing Global 101: How to Manage Your Websites Worldwide Using Drupal
Going Global 101: How to Manage Your Websites Worldwide Using Drupal
 
Introducing Workspace Preview System: Solve Your Content Preview Problems
Introducing Workspace Preview System: Solve Your Content Preview ProblemsIntroducing Workspace Preview System: Solve Your Content Preview Problems
Introducing Workspace Preview System: Solve Your Content Preview Problems
 
The Future of a Content-Driven World: How To Prepare Your Team
The Future of a Content-Driven World: How To Prepare Your TeamThe Future of a Content-Driven World: How To Prepare Your Team
The Future of a Content-Driven World: How To Prepare Your Team
 
How to Successfully Implement Headless Drupal
How to Successfully Implement Headless DrupalHow to Successfully Implement Headless Drupal
How to Successfully Implement Headless Drupal
 
How Wilson Sporting Goods Is Changing the Game with Experiential Commerce
 How Wilson Sporting Goods Is Changing the Game with Experiential Commerce How Wilson Sporting Goods Is Changing the Game with Experiential Commerce
How Wilson Sporting Goods Is Changing the Game with Experiential Commerce
 
From Stone Age-worthy Sites to Cohesive Content: How Trinity University is Us...
From Stone Age-worthy Sites to Cohesive Content: How Trinity University is Us...From Stone Age-worthy Sites to Cohesive Content: How Trinity University is Us...
From Stone Age-worthy Sites to Cohesive Content: How Trinity University is Us...
 
Acquia Content Hub: Connect Technologies & Extend Systems to Source Content
Acquia Content Hub: Connect Technologies & Extend Systems to Source ContentAcquia Content Hub: Connect Technologies & Extend Systems to Source Content
Acquia Content Hub: Connect Technologies & Extend Systems to Source Content
 
Updating the Salesforce Suite to Drupal 8: Major Changes for a Big Module
Updating the Salesforce Suite to Drupal 8: Major Changes for a Big ModuleUpdating the Salesforce Suite to Drupal 8: Major Changes for a Big Module
Updating the Salesforce Suite to Drupal 8: Major Changes for a Big Module
 
Decoupled Drupal Showcase: Using Drupal to Power Digital Signage
Decoupled Drupal Showcase: Using Drupal to Power Digital SignageDecoupled Drupal Showcase: Using Drupal to Power Digital Signage
Decoupled Drupal Showcase: Using Drupal to Power Digital Signage
 
Open Y: One Digital Platform for all YMCAs
Open Y: One Digital Platform for all YMCAsOpen Y: One Digital Platform for all YMCAs
Open Y: One Digital Platform for all YMCAs
 
A Future-Focused Digital Platform with Drupal 8
A Future-Focused Digital Platform with Drupal 8A Future-Focused Digital Platform with Drupal 8
A Future-Focused Digital Platform with Drupal 8
 

Similar to Drupal 8 Deep Dive: What It Means for Developers Now that REST Is in Core

PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
elliando dias
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
elliando dias
 
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
camp_drupal_ua
 

Similar to Drupal 8 Deep Dive: What It Means for Developers Now that REST Is in Core (20)

What's new in the Drupal 7 API?
What's new in the Drupal 7 API?What's new in the Drupal 7 API?
What's new in the Drupal 7 API?
 
Fatc
FatcFatc
Fatc
 
Doctrine and NoSQL
Doctrine and NoSQLDoctrine and NoSQL
Doctrine and NoSQL
 
Doctrine for NoSQL
Doctrine for NoSQLDoctrine for NoSQL
Doctrine for NoSQL
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in Perl
 
Intro to php
Intro to phpIntro to php
Intro to php
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platforms
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
Drupal 7 database api
Drupal 7 database api Drupal 7 database api
Drupal 7 database api
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW Workshop
 
Create a res tful services api in php.
Create a res tful services api in php.Create a res tful services api in php.
Create a res tful services api in php.
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
 
RESTful API 제대로 만들기
RESTful API 제대로 만들기RESTful API 제대로 만들기
RESTful API 제대로 만들기
 
Progressive Enhancment with Rails and React
Progressive Enhancment with Rails and ReactProgressive Enhancment with Rails and React
Progressive Enhancment with Rails and React
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 
Headless Drupal en pratique
Headless Drupal en pratiqueHeadless Drupal en pratique
Headless Drupal en pratique
 
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
 

More from Acquia

Taking Your Multi-Site Management at Scale to the Next Level
Taking Your Multi-Site Management at Scale to the Next LevelTaking Your Multi-Site Management at Scale to the Next Level
Taking Your Multi-Site Management at Scale to the Next Level
Acquia
 

More from Acquia (20)

Acquia_Adcetera Webinar_Marketing Automation.pdf
Acquia_Adcetera Webinar_Marketing Automation.pdfAcquia_Adcetera Webinar_Marketing Automation.pdf
Acquia_Adcetera Webinar_Marketing Automation.pdf
 
Acquia Webinar Deck - 9_13 .pdf
Acquia Webinar Deck - 9_13 .pdfAcquia Webinar Deck - 9_13 .pdf
Acquia Webinar Deck - 9_13 .pdf
 
Taking Your Multi-Site Management at Scale to the Next Level
Taking Your Multi-Site Management at Scale to the Next LevelTaking Your Multi-Site Management at Scale to the Next Level
Taking Your Multi-Site Management at Scale to the Next Level
 
CDP for Retail Webinar with Appnovation - Q2 2022.pdf
CDP for Retail Webinar with Appnovation - Q2 2022.pdfCDP for Retail Webinar with Appnovation - Q2 2022.pdf
CDP for Retail Webinar with Appnovation - Q2 2022.pdf
 
May Partner Bootcamp 2022
May Partner Bootcamp 2022May Partner Bootcamp 2022
May Partner Bootcamp 2022
 
April Partner Bootcamp 2022
April Partner Bootcamp 2022April Partner Bootcamp 2022
April Partner Bootcamp 2022
 
How to Unify Brand Experience: A Hootsuite Story
How to Unify Brand Experience: A Hootsuite Story How to Unify Brand Experience: A Hootsuite Story
How to Unify Brand Experience: A Hootsuite Story
 
Using Personas to Guide DAM Results: How Life Time Pumped Up Their UX and CX
Using Personas to Guide DAM Results: How Life Time Pumped Up Their UX and CXUsing Personas to Guide DAM Results: How Life Time Pumped Up Their UX and CX
Using Personas to Guide DAM Results: How Life Time Pumped Up Their UX and CX
 
Improve Code Quality and Time to Market: 100% Cloud-Based Development Workflow
Improve Code Quality and Time to Market: 100% Cloud-Based Development WorkflowImprove Code Quality and Time to Market: 100% Cloud-Based Development Workflow
Improve Code Quality and Time to Market: 100% Cloud-Based Development Workflow
 
September Partner Bootcamp
September Partner BootcampSeptember Partner Bootcamp
September Partner Bootcamp
 
August partner bootcamp
August partner bootcampAugust partner bootcamp
August partner bootcamp
 
July 2021 Partner Bootcamp
July  2021 Partner BootcampJuly  2021 Partner Bootcamp
July 2021 Partner Bootcamp
 
May Partner Bootcamp
May Partner BootcampMay Partner Bootcamp
May Partner Bootcamp
 
DRUPAL 7 END OF LIFE IS NEAR - MIGRATE TO DRUPAL 9 FAST AND EASY
DRUPAL 7 END OF LIFE IS NEAR - MIGRATE TO DRUPAL 9 FAST AND EASYDRUPAL 7 END OF LIFE IS NEAR - MIGRATE TO DRUPAL 9 FAST AND EASY
DRUPAL 7 END OF LIFE IS NEAR - MIGRATE TO DRUPAL 9 FAST AND EASY
 
Work While You Sleep: The CMO’s Guide to a 24/7/365 Lead Machine
Work While You Sleep: The CMO’s Guide to a 24/7/365 Lead MachineWork While You Sleep: The CMO’s Guide to a 24/7/365 Lead Machine
Work While You Sleep: The CMO’s Guide to a 24/7/365 Lead Machine
 
Acquia webinar: Leveraging Drupal to Bury Your Sales Team In B2B Leads
Acquia webinar: Leveraging Drupal to Bury Your Sales Team In B2B LeadsAcquia webinar: Leveraging Drupal to Bury Your Sales Team In B2B Leads
Acquia webinar: Leveraging Drupal to Bury Your Sales Team In B2B Leads
 
April partner bootcamp deck cookieless future
April partner bootcamp deck  cookieless futureApril partner bootcamp deck  cookieless future
April partner bootcamp deck cookieless future
 
How to enhance cx through personalised, automated solutions
How to enhance cx through personalised, automated solutionsHow to enhance cx through personalised, automated solutions
How to enhance cx through personalised, automated solutions
 
DRUPAL MIGRATIONS AND DRUPAL 9 INNOVATION: HOW PAC-12 DELIVERED DIGITALLY FOR...
DRUPAL MIGRATIONS AND DRUPAL 9 INNOVATION: HOW PAC-12 DELIVERED DIGITALLY FOR...DRUPAL MIGRATIONS AND DRUPAL 9 INNOVATION: HOW PAC-12 DELIVERED DIGITALLY FOR...
DRUPAL MIGRATIONS AND DRUPAL 9 INNOVATION: HOW PAC-12 DELIVERED DIGITALLY FOR...
 
Customer Experience (CX): 3 Key Factors Shaping CX Redesign in 2021
Customer Experience (CX): 3 Key Factors Shaping CX Redesign in 2021Customer Experience (CX): 3 Key Factors Shaping CX Redesign in 2021
Customer Experience (CX): 3 Key Factors Shaping CX Redesign in 2021
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Drupal 8 Deep Dive: What It Means for Developers Now that REST Is in Core

  • 1. Web APIs in Drupal 8 Larry Garfield, Senior Architect, Palantir.net Kyle Browning, Technical Consultant, Acquia
  • 2. Larry Garfield Senior Architect, Palantir.net Drupal Web Services Lead Who are we?
  • 3. Kyle Browning Technical Consultant, Acquia Services, and Drupal iOS SDK maintainer Who are we?
  • 4. What are Web Services(tm)?
  • 5. The Internet (TCP/IP) The Web (HTTP) Web Services (non-HTML) REST (REpresentational State Transfer)
  • 6. Collection of Resources Resource identified by URI Resource represented in a format Manipulate through Verbs/Methods Known hyperlinks to other Resources REST (Hypermedia)
  • 7. So what's wrong with Drupal 7?
  • 8. Drupal 7 function example_menu() { $items['my/page'] = array( 'title' => 'My page', 'page callback' => 'my_page_function', 'access arguments' => array('access content'), ); return $items; } Only map on path Very basic access control
  • 9. Drupal 7 function example_page_delivery_callback_alter(&$delivery_callback) { if (...) { $delivery_callback = 'example_deliver_page'; } } Happens after the page callback, so mostly useless.
  • 10. Drupal 7 →And oh yeah, globals ▪ $_GET ▪ drupal_add_http_header() ▪ print
  • 11. Drupal 7 Everything other than a full HTML page is an after-thought.
  • 12. So what's better in Drupal 8?
  • 13. Drupal 8 example.route: path: /my/page defaults: _controller: 'DrupalexampleControllerExampleController::page' _title: 'Example page' requirements: _permission: 'access_examples' _day: 'Tuesday' _method: 'GET' Multiple access checks Map on path,
  • 14. Drupal 8 Arbitrary custom logic goes here
  • 15. Drupal 8 Theming and page layout happen here
  • 16. Drupal 8 Everything's an HTTP Response. Sometimes that's a page.
  • 17. Drupal 8 →You can serve any type of response to a request →Wire directly to the routing system. →No duplicating routing anymore!
  • 18. Drupal 8 - Serialization module →Standard serialization/deserialization pipeline →Built on Symfony Serializer component $json = $this->serializer->serialize($entity, 'json'); $xml = $this->serializer->serialize($entity, 'xml'); $entity = $this->serializer->deserialize($json, 'Node' 'json'); Standard universal serialized format (for internal structure)!
  • 19. Drupal 8 - REST module →Core module for common pattern of REST usage →~RestWS →Uses Serialization →Define "Resource" Plugins ▪ GET/get(), PUT/put(), DELETE/delete() ▪ Return ResourceResponse ▪ Drupal will serialize()/deserialize() for you
  • 20. Drupal 8 - REST resources class DBLogResource extends ResourceBase { public function get($id = NULL) { if ($id) { $record = db_query("SELECT * FROM {watchdog} WHERE wid = :wid", [':wid' => $id]) ->fetchAssoc(); if (!empty($record)) { return new ResourceResponse($record); } throw new NotFoundHttpException(t('Log entry with ID @id was not found', ['@id' => $id])); } throw new HttpException(t('No log entry ID was provided')); } }
  • 21. Drupal 8 - REST resources All Content Entities are supported out-of-the-box ● Uses same URL as HTML page ● All supported formats, automatically ● Opt-in configuration Easily add your own resources, too Teach serializer about it (Normalizer) Create new Resource plugin Profit!!1!
  • 22. Drupal 8 - Content Negotiation Reverse proxies suck + Browsers suck even more = Accept-based negotiation is broken 90% of the time :-(
  • 23. Drupal 8 - Content Negotiation http://example.com/node/5?&_format=hal_json http://example.com/node/5?&_format=xml http://example.com/node/5?&_format=html (default)
  • 26. Drupal 8 - Hypermedia Links Coming soon! (8.1? As soon as someone works on it.) https://www.drupal.org/node/2113345
  • 27. What does Services module do?
  • 28. Drupal 8 - Services →Provide endpoint capabilities to put your API behind a centralized URL →Standardize on an approach to building non-REST APIs →Accept Header content negotiation →Gives us regular json response instead of hal_json →Config entities too!
  • 29. Drupal 8 - ServicesDefinition →Defines the ‘resource’ →Protein of Services in D8 →Route Access →Request method
  • 30. Drupal 8 - ServicesDefinition
  • 33. Lets grab a block
  • 36. And since everything is an entity.
  • 37. Drupal 8 - Views