SlideShare une entreprise Scribd logo
1  sur  24
How I built web services in CakePHP
Amsterdam
2016
Introduction
PHP Developer
at UK Web Media
in Weyhill, UK
http://www.ukwm.co.uk
Cyberstalk me!
https://twitter.com/YellDavid
https://github.com/davidyell
http://careers.stackoverflow.com/davidyell
http://uk.linkedin.com/in/davidyell
#cakephp on Freenode IRC
David Yell
aka Neon1024
Agenda
System architecture
Version 1
Version 2
Version 3
CakePHP 2
CakePHP 2
CakePHP 3
System architecture
CMS
Web
Service
Client websites
The
Internet
ApiUpdatable
Driver
Plugins
Read-only
Queue
Setup
/api/v1
Api
ApiAuth
Yey!
● Plugin architecture
● Self-contained
Boo!
● Single fat controller
● Lack of separation
● Less flexible
Routing
Request
Response
Plugins
Version 1
v1 prefix
The Fat Controller
Version 1
Api Plugin
/api/v1
● Hard to maintain
● Lack of flexibility
● Not DRY
● No separation of
concerns
● Custom views
Version 1
ApiAuth Plugin
/api/v1
● No standards
● Open GET params
● No security
Version 1
Setup
/api/v2
Yey!
●
Shares existing code
●
More generic
● Extensibility
● Per endpoint customisation
Boo!
●
Hard to create common filtering
● Too much code in AppController
●
Lacks separation
Routing
Request
Response
Application
Version 2
v2 prefix
AppController ProductsController
API Design choices
Pragmatic approach
Complex queries but more complete responses
Allows complete configured return
Flexible filtering and sorting
Specific use-cases
Further reading,
http://www.bravo-kernel.com/tags/api/
Version 3
Routing
Request
Response
api prefix
v3 route
ApiAppController
Crud plugin
Custom Crud actions
Contain class Filter class
Yey!
● Crud automation
● Free sorting and pagination
● Code separation
● Extensible
Boo!
● Complexity
Setup
/api/v3
ApiQuery Behavior
Version with prefixes
src/Controller/Api/V3/PackagesController.php
src/Controller/Api/V4/PackagesController.php
/api/v3/packages.json
/api/v4/packages.json
Crud plugin
friendsofcake/crud
Event driven scaffolding
Be lazy
Do less work
??
Profit
http://www.bravo-kernel.com/2015/04/how-to-build-a-cakephp-3-
rest-api-in-minutes/
Crud Index Action
Crud Index Action
Related data
Contain all the things
Version 3
Version 3
Filtering data
Match all the things
Version 3
Example queries
Get packages with related data, where line rental is included,
from provider id 4, matching an associated Table field, sorted
by price, on page 2.
/api/v3/packages.json
?verbose=true
&filter[line_rental_included]=true
&filter[provider_id]=4
&filter[Related.something]=foo
&site_id=n
&limit=20
&page=3
&sort=price
&direction=asc
Free with Crud plugin!
Version 3
Example queries
Get a specific list of packages in a certain order.
/api/v3/packages.json
?id[0]=19
&id[1]=17
&id[2]=11
&id[3]=43
&site_id=n
Lessons learned
Don't
● Single controller
● Filter in controller
Do
● Routing prefixes
● Crud plugin
● Authentication
● Create separation
● Integration testing
Toolset
friendsofcake/crud
friendsofcake/search
admad/cakephp-jwt-auth
muffin/webservice
league/fractal
https://www.getpostman.com/
Consuming the API
Cake 2
Custom data source
http://book.cakephp.org/2.0/en/models/datasources.html
Muffin/WebService Cake 3 driver
http://jedistirfry.co.uk/blog/2015-09/connecting-to-a-web-service/
Consuming the API
Cake 3
Thanks!
Questions?
Please rate my talk
https://joind.in/talk/e2065
Attend your local PHP Usergroup! http://php.ug/
http://osmihelp.org/donate

Contenu connexe

Tendances

Using Git with WordPress - Presented by Nigel Rodgers.
Using Git with WordPress - Presented by Nigel Rodgers.Using Git with WordPress - Presented by Nigel Rodgers.
Using Git with WordPress - Presented by Nigel Rodgers.WordCamp Harare
 
Building End to-End Web Apps Using TypeScript
Building End to-End Web Apps Using TypeScriptBuilding End to-End Web Apps Using TypeScript
Building End to-End Web Apps Using TypeScriptGil Fink
 
Web development meetingup
Web development meetingupWeb development meetingup
Web development meetingupPiTechnologies
 
Vaadin slides for @Devoxx 2012
Vaadin slides for @Devoxx 2012Vaadin slides for @Devoxx 2012
Vaadin slides for @Devoxx 2012Nicolas Fränkel
 
Robin Böhm - Angular 2 - code.talks 2015
Robin Böhm - Angular 2 - code.talks 2015Robin Böhm - Angular 2 - code.talks 2015
Robin Böhm - Angular 2 - code.talks 2015AboutYouGmbH
 
Git in 10 minutes (WordCamp Europe 2017)
Git in 10 minutes (WordCamp Europe 2017)Git in 10 minutes (WordCamp Europe 2017)
Git in 10 minutes (WordCamp Europe 2017)Borek Bernard
 
Creating real time applications with Angular and Firebase
Creating real time applications with Angular and FirebaseCreating real time applications with Angular and Firebase
Creating real time applications with Angular and FirebaseLoiane Groner
 
180929_NextBuild_From_Java_to_Kotlin
180929_NextBuild_From_Java_to_Kotlin180929_NextBuild_From_Java_to_Kotlin
180929_NextBuild_From_Java_to_KotlinPaulien van Alst
 
Untangle Your Front End Development with Visual Studio 2015
Untangle Your Front End Development with Visual Studio 2015Untangle Your Front End Development with Visual Studio 2015
Untangle Your Front End Development with Visual Studio 2015Scott Heckel
 
Going Global with WordPress Multilingual (WordCamp Denpasar 2016)
Going Global with WordPress Multilingual (WordCamp Denpasar 2016)Going Global with WordPress Multilingual (WordCamp Denpasar 2016)
Going Global with WordPress Multilingual (WordCamp Denpasar 2016)Dat Hoang
 
WordPress on the Jamstack by rtCamper Muhammad Muhsin @ WordPress Colombo Meetup
WordPress on the Jamstack by rtCamper Muhammad Muhsin @ WordPress Colombo MeetupWordPress on the Jamstack by rtCamper Muhammad Muhsin @ WordPress Colombo Meetup
WordPress on the Jamstack by rtCamper Muhammad Muhsin @ WordPress Colombo MeetuprtCamp
 
Women Who Mule - Workshop series: Create your own blog from scratch without a...
Women Who Mule - Workshop series: Create your own blog from scratch without a...Women Who Mule - Workshop series: Create your own blog from scratch without a...
Women Who Mule - Workshop series: Create your own blog from scratch without a...Alexandra N. Martinez
 
To The Word And Beyond! Extending WordPress Past a Simple Blog
To The Word And Beyond! Extending WordPress Past a Simple BlogTo The Word And Beyond! Extending WordPress Past a Simple Blog
To The Word And Beyond! Extending WordPress Past a Simple BlogMeagan Hanes
 

Tendances (20)

MJML API @ Paris API
MJML API  @ Paris APIMJML API  @ Paris API
MJML API @ Paris API
 
Using Git with WordPress - Presented by Nigel Rodgers.
Using Git with WordPress - Presented by Nigel Rodgers.Using Git with WordPress - Presented by Nigel Rodgers.
Using Git with WordPress - Presented by Nigel Rodgers.
 
Building End to-End Web Apps Using TypeScript
Building End to-End Web Apps Using TypeScriptBuilding End to-End Web Apps Using TypeScript
Building End to-End Web Apps Using TypeScript
 
Web development meetingup
Web development meetingupWeb development meetingup
Web development meetingup
 
Vaadin slides for @Devoxx 2012
Vaadin slides for @Devoxx 2012Vaadin slides for @Devoxx 2012
Vaadin slides for @Devoxx 2012
 
Robin Böhm - Angular 2 - code.talks 2015
Robin Böhm - Angular 2 - code.talks 2015Robin Böhm - Angular 2 - code.talks 2015
Robin Böhm - Angular 2 - code.talks 2015
 
Git in 10 minutes (WordCamp Europe 2017)
Git in 10 minutes (WordCamp Europe 2017)Git in 10 minutes (WordCamp Europe 2017)
Git in 10 minutes (WordCamp Europe 2017)
 
Creating real time applications with Angular and Firebase
Creating real time applications with Angular and FirebaseCreating real time applications with Angular and Firebase
Creating real time applications with Angular and Firebase
 
180929_NextBuild_From_Java_to_Kotlin
180929_NextBuild_From_Java_to_Kotlin180929_NextBuild_From_Java_to_Kotlin
180929_NextBuild_From_Java_to_Kotlin
 
Plugin for CakePHP2.0
Plugin for CakePHP2.0Plugin for CakePHP2.0
Plugin for CakePHP2.0
 
Untangle Your Front End Development with Visual Studio 2015
Untangle Your Front End Development with Visual Studio 2015Untangle Your Front End Development with Visual Studio 2015
Untangle Your Front End Development with Visual Studio 2015
 
Going Global with WordPress Multilingual (WordCamp Denpasar 2016)
Going Global with WordPress Multilingual (WordCamp Denpasar 2016)Going Global with WordPress Multilingual (WordCamp Denpasar 2016)
Going Global with WordPress Multilingual (WordCamp Denpasar 2016)
 
MVA-Transcript
MVA-TranscriptMVA-Transcript
MVA-Transcript
 
PWA - Progressive Web App
PWA - Progressive Web AppPWA - Progressive Web App
PWA - Progressive Web App
 
WordPress on the Jamstack by rtCamper Muhammad Muhsin @ WordPress Colombo Meetup
WordPress on the Jamstack by rtCamper Muhammad Muhsin @ WordPress Colombo MeetupWordPress on the Jamstack by rtCamper Muhammad Muhsin @ WordPress Colombo Meetup
WordPress on the Jamstack by rtCamper Muhammad Muhsin @ WordPress Colombo Meetup
 
That worked before
That worked beforeThat worked before
That worked before
 
Women Who Mule - Workshop series: Create your own blog from scratch without a...
Women Who Mule - Workshop series: Create your own blog from scratch without a...Women Who Mule - Workshop series: Create your own blog from scratch without a...
Women Who Mule - Workshop series: Create your own blog from scratch without a...
 
To The Word And Beyond! Extending WordPress Past a Simple Blog
To The Word And Beyond! Extending WordPress Past a Simple BlogTo The Word And Beyond! Extending WordPress Past a Simple Blog
To The Word And Beyond! Extending WordPress Past a Simple Blog
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
EVOLVE'13 | Keynote | Richard Brown
EVOLVE'13 | Keynote | Richard BrownEVOLVE'13 | Keynote | Richard Brown
EVOLVE'13 | Keynote | Richard Brown
 

Similaire à How I built web services in CakePHP

Make web as webapp
Make web as webappMake web as webapp
Make web as webappFred Lin
 
Don't Code, Bake. An introduction to CakePHP ~PHP Hampshire Oct 2014
Don't Code, Bake. An introduction to CakePHP ~PHP Hampshire Oct 2014Don't Code, Bake. An introduction to CakePHP ~PHP Hampshire Oct 2014
Don't Code, Bake. An introduction to CakePHP ~PHP Hampshire Oct 2014David Yell
 
PHP South Coast - Don't code bake, an introduction to CakePHP 3
PHP South Coast - Don't code bake, an introduction to CakePHP 3PHP South Coast - Don't code bake, an introduction to CakePHP 3
PHP South Coast - Don't code bake, an introduction to CakePHP 3David Yell
 
GoPro, Inc. Case study: Dive into the details of our web applications
GoPro, Inc. Case study: Dive into the details of our web applicationsGoPro, Inc. Case study: Dive into the details of our web applications
GoPro, Inc. Case study: Dive into the details of our web applicationsAndrew Maxwell
 
Joomlatools Platform v2.0
Joomlatools Platform v2.0Joomlatools Platform v2.0
Joomlatools Platform v2.0Joomlatools
 
Pro Magento MeetUp #4 - Upgrade Compatibility Tool, Sergii Ivashchenko
Pro Magento MeetUp #4 - Upgrade Compatibility Tool, Sergii IvashchenkoPro Magento MeetUp #4 - Upgrade Compatibility Tool, Sergii Ivashchenko
Pro Magento MeetUp #4 - Upgrade Compatibility Tool, Sergii IvashchenkoPro Magento Community
 
Go Pro, Inc. Case Study: Dive into the details of our node.js applications
Go Pro, Inc. Case Study: Dive into the details of our node.js applicationsGo Pro, Inc. Case Study: Dive into the details of our node.js applications
Go Pro, Inc. Case Study: Dive into the details of our node.js applicationsAndrew Maxwell
 
Webplatform And Php
Webplatform And PhpWebplatform And Php
Webplatform And PhpPierre Joye
 
Introducing ASP.NET vNext - A tour of the new ASP.NET platform
Introducing ASP.NET vNext - A tour of the new ASP.NET platformIntroducing ASP.NET vNext - A tour of the new ASP.NET platform
Introducing ASP.NET vNext - A tour of the new ASP.NET platformJeffrey T. Fritz
 
Modular Web Applications based on OSGi - Jochen Hiller
Modular Web Applications based on OSGi - Jochen HillerModular Web Applications based on OSGi - Jochen Hiller
Modular Web Applications based on OSGi - Jochen Hillermfrancis
 
The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014
The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014
The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014Enea Gabriel
 
Introducing ASP.NET vNext – The Future of .NET on the Server | FalafelCON 2014
Introducing ASP.NET vNext – The Future of .NET on the Server | FalafelCON 2014Introducing ASP.NET vNext – The Future of .NET on the Server | FalafelCON 2014
Introducing ASP.NET vNext – The Future of .NET on the Server | FalafelCON 2014FalafelSoftware
 
Making sense of the front-end, for PHP developers
Making sense of the front-end, for PHP developersMaking sense of the front-end, for PHP developers
Making sense of the front-end, for PHP developersLewiz
 
Joomlatools Platform v1.0
Joomlatools Platform v1.0Joomlatools Platform v1.0
Joomlatools Platform v1.0Joomlatools
 
Php Performance On Windows
Php Performance On WindowsPhp Performance On Windows
Php Performance On Windowsruslany
 
Rev it up with php on windows
Rev it up with php on windowsRev it up with php on windows
Rev it up with php on windowsJosh Holmes
 
Codeception: introduction to php testing
Codeception: introduction to php testingCodeception: introduction to php testing
Codeception: introduction to php testingEngineor
 
Apigility introduction v2 (glasgow php)
Apigility introduction v2 (glasgow php)Apigility introduction v2 (glasgow php)
Apigility introduction v2 (glasgow php)Engineor
 
Web componenet using angular element
Web componenet using angular elementWeb componenet using angular element
Web componenet using angular elementHimanshu Tamrakar
 
MadridDevops September 2014: "From chef09 to chef11, one approach to devops"
MadridDevops September 2014: "From chef09 to chef11, one approach to devops"MadridDevops September 2014: "From chef09 to chef11, one approach to devops"
MadridDevops September 2014: "From chef09 to chef11, one approach to devops"Antonio Peña
 

Similaire à How I built web services in CakePHP (20)

Make web as webapp
Make web as webappMake web as webapp
Make web as webapp
 
Don't Code, Bake. An introduction to CakePHP ~PHP Hampshire Oct 2014
Don't Code, Bake. An introduction to CakePHP ~PHP Hampshire Oct 2014Don't Code, Bake. An introduction to CakePHP ~PHP Hampshire Oct 2014
Don't Code, Bake. An introduction to CakePHP ~PHP Hampshire Oct 2014
 
PHP South Coast - Don't code bake, an introduction to CakePHP 3
PHP South Coast - Don't code bake, an introduction to CakePHP 3PHP South Coast - Don't code bake, an introduction to CakePHP 3
PHP South Coast - Don't code bake, an introduction to CakePHP 3
 
GoPro, Inc. Case study: Dive into the details of our web applications
GoPro, Inc. Case study: Dive into the details of our web applicationsGoPro, Inc. Case study: Dive into the details of our web applications
GoPro, Inc. Case study: Dive into the details of our web applications
 
Joomlatools Platform v2.0
Joomlatools Platform v2.0Joomlatools Platform v2.0
Joomlatools Platform v2.0
 
Pro Magento MeetUp #4 - Upgrade Compatibility Tool, Sergii Ivashchenko
Pro Magento MeetUp #4 - Upgrade Compatibility Tool, Sergii IvashchenkoPro Magento MeetUp #4 - Upgrade Compatibility Tool, Sergii Ivashchenko
Pro Magento MeetUp #4 - Upgrade Compatibility Tool, Sergii Ivashchenko
 
Go Pro, Inc. Case Study: Dive into the details of our node.js applications
Go Pro, Inc. Case Study: Dive into the details of our node.js applicationsGo Pro, Inc. Case Study: Dive into the details of our node.js applications
Go Pro, Inc. Case Study: Dive into the details of our node.js applications
 
Webplatform And Php
Webplatform And PhpWebplatform And Php
Webplatform And Php
 
Introducing ASP.NET vNext - A tour of the new ASP.NET platform
Introducing ASP.NET vNext - A tour of the new ASP.NET platformIntroducing ASP.NET vNext - A tour of the new ASP.NET platform
Introducing ASP.NET vNext - A tour of the new ASP.NET platform
 
Modular Web Applications based on OSGi - Jochen Hiller
Modular Web Applications based on OSGi - Jochen HillerModular Web Applications based on OSGi - Jochen Hiller
Modular Web Applications based on OSGi - Jochen Hiller
 
The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014
The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014
The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014
 
Introducing ASP.NET vNext – The Future of .NET on the Server | FalafelCON 2014
Introducing ASP.NET vNext – The Future of .NET on the Server | FalafelCON 2014Introducing ASP.NET vNext – The Future of .NET on the Server | FalafelCON 2014
Introducing ASP.NET vNext – The Future of .NET on the Server | FalafelCON 2014
 
Making sense of the front-end, for PHP developers
Making sense of the front-end, for PHP developersMaking sense of the front-end, for PHP developers
Making sense of the front-end, for PHP developers
 
Joomlatools Platform v1.0
Joomlatools Platform v1.0Joomlatools Platform v1.0
Joomlatools Platform v1.0
 
Php Performance On Windows
Php Performance On WindowsPhp Performance On Windows
Php Performance On Windows
 
Rev it up with php on windows
Rev it up with php on windowsRev it up with php on windows
Rev it up with php on windows
 
Codeception: introduction to php testing
Codeception: introduction to php testingCodeception: introduction to php testing
Codeception: introduction to php testing
 
Apigility introduction v2 (glasgow php)
Apigility introduction v2 (glasgow php)Apigility introduction v2 (glasgow php)
Apigility introduction v2 (glasgow php)
 
Web componenet using angular element
Web componenet using angular elementWeb componenet using angular element
Web componenet using angular element
 
MadridDevops September 2014: "From chef09 to chef11, one approach to devops"
MadridDevops September 2014: "From chef09 to chef11, one approach to devops"MadridDevops September 2014: "From chef09 to chef11, one approach to devops"
MadridDevops September 2014: "From chef09 to chef11, one approach to devops"
 

Dernier

Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 

Dernier (20)

Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 

How I built web services in CakePHP

Notes de l'éditeur

  1. Thanks for voting on my talk, I really appreciate it. Nearly 10 years commercial experience, mostly agencies doing campaign work. Started with HTML on GeoCities. Self-taught in PHP, started with CakePHP on 1.3 in 2008 ish and am in the Friends of Cake group UKWM do campaign and affiliate marketing work, I work mostly on the telecoms sites comparing broadband, tv and phone All our stuff is CakePHP 2 or 3, I'm migrating stuff as and when I have time This is the first run of this presentation so be gentle! I will hopefully have some time at the end for questions.
  2. It's what I do for my job v1 is the first api I ever built! It's a read only web service Built by myself, used by myself Work in progress We are silo'd at work, so you guys are doing my code review for me!
  3. The web service driver is a Datasource in Cake 2, and a web service driver in Cake 3. The use-case is a centrally managed data-store ApiUpdatable has a queue to schedule updates from the client site It also has a shell run on a cron Thin clients pull data from the web service on render and use local cache Multiple versions of the API with clients being migrated over
  4. First ever api I built A plugin seemed logical at the time Coded first rather than designing it Difficult containing deep associations, 4-5 levels Ended up filtering data in the view, so the pagination meta was wrong Index method in ApiController is 247 lines long!
  5. If your controller looks like this, stop, and rethink
  6. Not flexible enough to expand to cover new use-cases easily Plugin needs tagging and releasing Duplicating functionality which already exists in the application Manual work to create the views
  7. Who knows what past me was thinking with this one. Even the templates are in the other plugin!
  8. All base endpoint methods are in the AppController Overload the methods as needed Extended methods means filtering would be complex on a per endpoint basis Never even made it out of the branch!
  9. Reqs: Allows for complex sorting and filtering combinations Makes my client implementation simple Full comparison table data Pragmatic approach, practice rather than theory Fulfils use-cases of complex full data returns Not using the RESTful routing Hidden the _matchingData Focus on simplicity for the client The utopian vision of everything being achievable
  10. Controller inheritance Crud plugin makes it easy Custom actions to call behavour methods on the query Behaviour uses custom finders to modify query Uses the ORMs stackable finders feature Doesn't adhere to REST standard, pragmatic and solo! ;) Filter and contain classes implement an interface, and customised per endpoint As Jose said in the workshop, don't be scared to go outside the framework Related data class also deals with sortable whitelist Luckily I have only 5 endpoints, 2 primary ones
  11. Neat code separation Can still inherit from ApiController Easy to run multiple versions from the same app
  12. Can help you build a basic api in literally minutes! Comes with pagination and sorting out of the box Has various api listeners, Api ApiPaginator ApiQueryLog Search listener implements the friendsofcake/search plugin Not as complicated as it appears, I'm working on the docs, so any contributions welcome!
  13. Copy and paste of the default crud action Just added some extra methods to hook into the query object The methods just look for the behaviour and call it's custom finders on the query
  14. Example Crud index action method _table is the current table, proxied call to Controller::loadModel() in Crud core Just passing a Cake\ORM\Query object Awesome because it's lazy I can build the query programatically and execute it later
  15. Relies on awesome Cake 3 ORM with closures in my contains to filter my associations Highly customisable Boss asked to remove pricing, comment out the line, job done, 2 mins – comment because I know he'll change his mind ;) Low impact, as it's tied to a single endpoint Lots of code though, so can look daunting Manages both Joins and Contains, as some fields must be joined for filtering and sorting Lives in src/Lib/Api/RelatedData
  16. Build filters as an array in the url I can pass all the filters around by just passing the array Allow for highly complex filtering Flexible and easy for clients to understand Has custom field filters too such as minPrice and maxPrice which map to the price field Lives in src/Lib/Api/Filters
  17. Might not want to expose your schema Could use a custom JSON view or use Fractal Can return a complete response for the client implementation
  18. For affiliate marketing comparison tables we need things in an arbitrary order set in the client site CMS Again, - Might not want to expose your schema - Could use a custom JSON view or use Fractal
  19. Routing prefixes good for versioning, as they can be nested! So why not an api prefix, with a v2 prefix and v3 prefix? Don't be constrained by the framework where it doesn't make sense. Not all of your code needs to fit into the framework, but check first! Theoretical paralysis, too much thinking not enough doing. Be pragmatic. Create a branch, try a thing, ditch it and start over. Three branches before sorting worked! Testing using json fixture files
  20. Postman client for testing your endpoints yourself
  21. Cake 2 ApiUpdatable behaviour swaps the datasource based on if the query has the ‘api’ => true option set in the find conditions using a callback Data returned as json array
  22. Service info configured in your app.php under Webservices config key Will return json entities directly from a cake 3 endpoint
  23. If you'd like to discuss anything in my talk, please come see me for a chat.