SlideShare ist ein Scribd-Unternehmen logo
1 von 59
REST in Peace
API DEVELOPMENT IN DRUPAL
Kate Marshalkina
Konstantin Komelin
Drupal Consultant from Moscow who fell in
love with Drupal in 2011.
Interested in i18n, distributions and Drupal 8.
Path Breadcrumbs co-maintainer.
@kalabro
Drupal Consultant from Saint Petersburg
Co-founder of local Drupal Community
Drupal Trainer at MorningCurve
@kkomelin
Let’s REST
Headless?!
What is API for?
Mobile Apps
API
Microservices
API
Frontend Apps
API
What is REST?
Resource
Representation
GET /items
POST /items
GET /items/1
PUT /items/1
DELETE /items/1
Methods
REpresentational State Transfer
RESTful or RESTless
REST in Drupal
Services RestWS RESTful Endpoint Drupal 8
Popularity
Documentation
Extensibility
Authentication
Performance
Auto API Docs
Versioning
Services
https://www.drupal.org/project/services
“A standardized solution of integrating
external applications with Drupal.”
37,085 sites use this module.
Popularity: ★★★★★
RESTful Web Services
https://www.drupal.org/project/restws
“Builds upon the Entity API, to provide support for all entity types out of the box.”
4,746 sites use this module.
Popularity: ★★★
RESTful
https://www.drupal.org/project/restful
https://github.com/RESTful-Drupal/restful
“This module allows Drupal to be operated via
RESTful HTTP requests, using best practices for
security, performance, and usability.”
“Audience is developers and not site builders.”
395 sites use this module.
Popularity: ★★
Endpoint
https://www.drupal.org/project/endpoint
“Endpoint is really light, fast and flexible, that makes it a good solution
for projects where Drupal role is mobile backend and single-page app
backend.”
7 sites use this module.
Popularity: ★
REST-focused alternative to High-performance JavaScript callback handler
https://www.drupal.org/project/js
Drupal 8 REST
Core + https://www.drupal.org/project/restui
“In Drupal 8 core, interactions with content
entities are supported via a REST interface.
The REST module is extensible, and
modules that wish to offer other services
can implement Resource Plugins.”
Popularity: ★★
Services RestWS RESTful Endpoint Drupal 8
Popularity
Documentation
Extensibility
Authentication
Performance
Auto API Docs
Versioning
Services RestWS RESTful Endpoint Drupal 8
Popularity
Documentation
Extensibility
Authentication
Performance
Auto API Docs
Versioning
Project docs API docs (hooks) UI Examples Videos
Services ★★★ ★★★★ ★★★★ ★★★ ★★★★
RestWS ★★★ ★★★★ ★ ★★★★ ★
RESTful ★★★★★ ★★★★★ ★★ ★★★★★ ★★
Endpoint ★★ ★★ ★ ★ ★
Drupal 8 ★★★ ★★★ ★★★ ★★★ ★★★
Documentation & Quick Start
Services RestWS RESTful Endpoint Drupal 8
Popularity
Documentation
Extensibility
Authentication
Performance
Auto API Docs
Versioning
Extensibility & hooks
Services RestWS RESTful Endpoint Drupal 8
Popularity
Documentation
Extensibility
Authentication
Performance
Auto API Docs
Versioning
Total lines of PHP code
Without comments, tests
and whitespace
Hooks
Services 15,000 6,000 18
RestWS 3,000 1,000 7
RESTful 18,000 6,000 1
Endpoint 300 300 -
Drupal 8 5,000 1 3
Code Statistics
Services
Custom architecture, ~18 hooks (13 — alter)
To create a custom resource:
1. Implement hook_services_resources()
2. Write custom callbacks
RestWS
Entity API + 7 hooks
To create a custom resource:
1. Implement hook_restws_resource_info()
2. Create controller class on top of RestWSResourceControllerInterface
RESTful
Ctools plugins, Entity API, OOP
To create a custom resource:
1. Implement hook_ctools_plugin_directory ()
2. Create controller class on top of RestfulEntityBase / RestfulInterface
Endpoint
Custom routing function.
To create a custom resource:
1. Create /api.php with an array of endpoints.
2. Call endpoint_route() from that file.
Drupal 8 REST
Plugin Manager, Config Manager, Routes, Annotations etc.
To create a custom resource:
1. Create controller on top of ResourceBase / ResourceInterface.
2. Save it as src/Plugin/rest/resource/MyCustomResource.php inside your module.
To enable endpoint for existing resource:
1. Write/paste resource settings into rest.settings.yml.
2. Create config/install/rest.settings.yml inside your module.
Services RestWS RESTful Endpoint Drupal 8
Popularity
Documentation
Extensibility
Authentication
Performance
Auto API Docs
Versioning
Security & Authentication
Security & Authentication
0. X-CSRF-Token
1. Cookie Auth
2. HTTP Basic Auth
3. Token Auth
4. OAuth
5. Oauth2
X-CSRF-Token
HTTP Header to prevent Cross-Site Request Forgery for session based authentication.
For writing methods: POST, PUT, PATCH, DELETE.
Services RestWS RESTful Endpoint Drupal 8
✔️ ✔️ ✔️ ✖️ ✔️
services/session/tok
en
restws/session/
token
api/session/
token
rest/session/
token
Cookie Auth
Drupal build-in auth mechanism.
1. Client sends auth request (user / password).
2. Server returns session cookie in Set-Cookie header.
3. Client makes further requests with Cookie: SESSb7f18cc=pvOhLNLdNNs7BkwbX8… header.
Services RestWS RESTful Endpoint Drupal 8
✔️ ✔️ ✔️ ✔️ ✔️
HTTP Basic Auth
Username and password are sent on every request (base64):
Authorization: Basic aHR0cHdhdGNoOmY=
Services RestWS RESTful Endpoint Drupal 8
✔️ ✔️ ✔️ ✖️ ✔️
Token Auth
Server returns token instead of Set-Cookie.
{ access_token: "7P1bwJtBTSKm-f_UHZFa6m2VWtyLNA8jHRiKUbhNwMQ",
type: "Bearer",
expires_in: 39584,
refresh_token: "Ch9p0Q4KZjisw-vGDzjAQW583bj6He6eiRZOp1ovFLQ" }
(Example from Restful).
Solves some cookies problems with CDNs, session store, CSRF, CORS.
Services RestWS RESTful Endpoint Drupal 8
✖️ ✖️ ✔️ ✖️ ✖️
See #1494132
OAuth implementations in Drupal:
1. OAuth 1.0: https://www.drupal.org/project/oauth
2. OAuth 2.0: https://www.drupal.org/project/oauth2_server
OAuth & OAuth2
Services RestWS RESTful Endpoint Drupal 8
OAuth ✔️ ✖️ ✖️ ✖️ ✖️*
OAuth2 Server ✔️ ✖️ ✔️ ✖️ ✖️
Services RestWS RESTful Endpoint Drupal 8
Popularity
Documentation
Extensibility
Authentication
Performance
Auto API Docs
Versioning
Performance
& Speed
How did we count?
• Ubuntu 14.04, Nginx 1.8.0, Mariadb 10.0.20, PHP 5.5.9 with php5-fpm, 1GB RAM
• Minimal Drupal Profile
• Node with just Title and Body
• Disabled Drupal cache
• Anonymous requests
• HTTP POST to create entities
• Apache Benchmark (ab)
• Clean database after each ab run
Services RestWS RESTful Endpoint Drupal 8
Popularity
Documentation
Extensibility
Authentication
Performance
Auto API Docs
Versioning
From apiary.io
Services Documentation API
https://www.drupal.org/project/services_documentation
Self Documenting REST API
https://www.drupal.org/project/rest_api_doc (7.x)
RESTful OPTIONS Request
Self Documenting REST API
https://www.drupal.org/project/rest_api_doc (8.x)
Services RestWS RESTful Endpoint Drupal 8
Popularity
Documentation
Extensibility
Authentication
Performance
Auto API Docs
Versioning
1. Versioning API
2. Multiple endpoints: /api/v1, /api/v2/
Versioning in Services
Built-in resource versioning.
Versioning in RESTful
Services RestWS RESTful Endpoint Drupal 8
Popularity
Documentation
Extensibility
Authentication
Performance
Auto API Docs
Versioning
Better to make a difference
together than make it
different alone
Leave feedback
through Picback
http://promokids.github.io/picback
konstantin@komelin.com
@kkomelin
marshalkina@gmail.com
@kalabro
Bonus: Drupal as an API Client
1. drupal_http_request()/ curl_exec()
2. RESTClient — Wrapper for 1.
3. Guzzle — PHP HTTP client
4. Feeds — for GET only
5. Clients — Pluggable client, supports Services endpoints
6. Remote Entity — Entity API + Clients
7. WSData — Alternative to Remote Entity
8. Integration with popular APIs: Twitter, Facebook, Dropbox etc.
9. Saucier — A Node.JS framework for Drupal API consumption.

Weitere ähnliche Inhalte

Was ist angesagt?

ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
habib_786
 

Was ist angesagt? (20)

An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple Steps
 
Rest API with Swagger and NodeJS
Rest API with Swagger and NodeJSRest API with Swagger and NodeJS
Rest API with Swagger and NodeJS
 
Introduction to REST - API
Introduction to REST - APIIntroduction to REST - API
Introduction to REST - API
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | Edureka
 
REST API
REST APIREST API
REST API
 
Angular
AngularAngular
Angular
 
What is Swagger?
What is Swagger?What is Swagger?
What is Swagger?
 
API for Beginners
API for BeginnersAPI for Beginners
API for Beginners
 
.Net Core
.Net Core.Net Core
.Net Core
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Restful api
Restful apiRestful api
Restful api
 
What’s New in Angular 14?
What’s New in Angular 14?What’s New in Angular 14?
What’s New in Angular 14?
 
HeadLess Drupal
HeadLess DrupalHeadLess Drupal
HeadLess Drupal
 
Designing APIs with OpenAPI Spec
Designing APIs with OpenAPI SpecDesigning APIs with OpenAPI Spec
Designing APIs with OpenAPI Spec
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentation
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & Development
 
Web API Basics
Web API BasicsWeb API Basics
Web API Basics
 

Andere mochten auch

RESTful Web Services in Drupal7
RESTful Web Services in Drupal7RESTful Web Services in Drupal7
RESTful Web Services in Drupal7
bmeme
 
Protect you site from CSRF
Protect you site from CSRFProtect you site from CSRF
Protect you site from CSRF
Acquia
 

Andere mochten auch (9)

Drupal 8 Authentication
Drupal 8 AuthenticationDrupal 8 Authentication
Drupal 8 Authentication
 
RESTful Web Services in Drupal7
RESTful Web Services in Drupal7RESTful Web Services in Drupal7
RESTful Web Services in Drupal7
 
Protect you site from CSRF
Protect you site from CSRFProtect you site from CSRF
Protect you site from CSRF
 
Open Source == Money
Open Source == MoneyOpen Source == Money
Open Source == Money
 
Scaling drupal horizontally and in cloud
Scaling drupal horizontally and in cloudScaling drupal horizontally and in cloud
Scaling drupal horizontally and in cloud
 
Scaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and more
Scaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and moreScaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and more
Scaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and more
 
Drupal 8 Deep Dive: What It Means for Developers Now that REST Is in Core
Drupal 8 Deep Dive: What It Means for Developers Now that REST Is in Core Drupal 8 Deep Dive: What It Means for Developers Now that REST Is in Core
Drupal 8 Deep Dive: What It Means for Developers Now that REST Is in Core
 
Philippines national-climate-change-action-plan
Philippines national-climate-change-action-planPhilippines national-climate-change-action-plan
Philippines national-climate-change-action-plan
 
Docker and Go: why did we decide to write Docker in Go?
Docker and Go: why did we decide to write Docker in Go?Docker and Go: why did we decide to write Docker in Go?
Docker and Go: why did we decide to write Docker in Go?
 

Ähnlich wie REST in Peace

Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
catherinewall
 
Create Home Directories on Storage Using WFA and ServiceNow integration
Create Home Directories on Storage Using WFA and ServiceNow integrationCreate Home Directories on Storage Using WFA and ServiceNow integration
Create Home Directories on Storage Using WFA and ServiceNow integration
Rutul Shah
 

Ähnlich wie REST in Peace (20)

StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop Overview
 
DEVNET-1136 Cisco ONE Enterprise Cloud Suite for Infrastructure Management.
DEVNET-1136	Cisco ONE Enterprise Cloud Suite for Infrastructure Management.DEVNET-1136	Cisco ONE Enterprise Cloud Suite for Infrastructure Management.
DEVNET-1136 Cisco ONE Enterprise Cloud Suite for Infrastructure Management.
 
Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014
Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014
Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014
 
Crafting APIs
Crafting APIsCrafting APIs
Crafting APIs
 
Meetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfMeetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdf
 
RESTful API-centric Universe
RESTful API-centric UniverseRESTful API-centric Universe
RESTful API-centric Universe
 
Build your APIs with apigility
Build your APIs with apigilityBuild your APIs with apigility
Build your APIs with apigility
 
Automate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon ViennaAutomate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon Vienna
 
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexusMicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
 
Drupal In The Cloud
Drupal In The CloudDrupal In The Cloud
Drupal In The Cloud
 
Kubernetes for the PHP developer
Kubernetes for the PHP developerKubernetes for the PHP developer
Kubernetes for the PHP developer
 
Introduction to CloudStack API
Introduction to CloudStack APIIntroduction to CloudStack API
Introduction to CloudStack API
 
Design Summit - RESTful API Overview - John Hardy
Design Summit - RESTful API Overview - John HardyDesign Summit - RESTful API Overview - John Hardy
Design Summit - RESTful API Overview - John Hardy
 
Micro service architecture
Micro service architectureMicro service architecture
Micro service architecture
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Кирилл Толкачев. Микросервисы: огонь, вода и девопс
Кирилл Толкачев. Микросервисы: огонь, вода и девопсКирилл Толкачев. Микросервисы: огонь, вода и девопс
Кирилл Толкачев. Микросервисы: огонь, вода и девопс
 
Operator SDK for K8s using Go
Operator SDK for K8s using GoOperator SDK for K8s using Go
Operator SDK for K8s using Go
 
ITB2016 - Building ColdFusion RESTFul Services
ITB2016 - Building ColdFusion RESTFul ServicesITB2016 - Building ColdFusion RESTFul Services
ITB2016 - Building ColdFusion RESTFul Services
 
Create Home Directories on Storage Using WFA and ServiceNow integration
Create Home Directories on Storage Using WFA and ServiceNow integrationCreate Home Directories on Storage Using WFA and ServiceNow integration
Create Home Directories on Storage Using WFA and ServiceNow integration
 
New and smart way to develop microservice for istio with micro profile
New and smart way to develop microservice for istio with micro profileNew and smart way to develop microservice for istio with micro profile
New and smart way to develop microservice for istio with micro profile
 

Mehr von Kate Marshalkina

Mehr von Kate Marshalkina (6)

Drupal 8: Теперь со вкусом Symfony
Drupal 8: Теперь со вкусом SymfonyDrupal 8: Теперь со вкусом Symfony
Drupal 8: Теперь со вкусом Symfony
 
Who is a Good Drupal Developer?
 Who is a Good Drupal Developer? Who is a Good Drupal Developer?
Who is a Good Drupal Developer?
 
Panels and Page Manager в Drupal 8
Panels and Page Manager в Drupal 8Panels and Page Manager в Drupal 8
Panels and Page Manager в Drupal 8
 
Drupal meets PostgreSQL for DrupalCamp MSK 2014
Drupal meets PostgreSQL for DrupalCamp MSK 2014Drupal meets PostgreSQL for DrupalCamp MSK 2014
Drupal meets PostgreSQL for DrupalCamp MSK 2014
 
Drupalcon Amsterdam ‘14 for Symfoniacs
Drupalcon Amsterdam ‘14 for SymfoniacsDrupalcon Amsterdam ‘14 for Symfoniacs
Drupalcon Amsterdam ‘14 for Symfoniacs
 
Multilingual Drupal 8
Multilingual Drupal 8Multilingual Drupal 8
Multilingual Drupal 8
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

REST in Peace