SlideShare une entreprise Scribd logo
1  sur  12
What is REST?
REST (Representational State Transfer) is a style of
software architecture mainly used for web services to
communicate between servers and clients using
existing features of the HTTP protocol.
The main HTTP verbs/methods used in REST are GET,
POST, PUT and DELETE
http://en.wikipedia.org/wiki/REST
Most companies online who offer APIs and webservices use REST.
Who’s using REST?
Why use REST?
You’ve already wrote the code! Use your existing code
with little changes.
Open your application to the public. Allow other
developers to integrate your application into their projects
or extend the functionality of your application.
Create applications on multiple platforms. Using your
REST API you can build mobile and desktop applications
using your existing code base.
REST in CakePHP
REST in CakePHP is simple.
Add RESTful controllers to Router::mapResources() to set up
default routes in /config/router.php.
Add desired extensions to Router::parseExtension() eg. xml,
json, yaml, etc. in /config/router.php.
Add RequestHandler component to controllers with REST
functionality.
http://book.cakephp.org/view/1238/REST
CakePHP RESTful routing
HTTP Method URL Controller Action
GET /recipes.ext RecipesController::index()
GET /recipes/123.ext RecipesController::view(123)
POST /recipes.ext RecipesController::add()
PUT /recipes/123.ext RecipesController::edit(123)
DELETE /recipes/123.ext RecipesController::delete(123)
POST /recipes/123.ext RecipesController::edit(123)
Custom RESTful routing
If you have additional methods in your controller that don’t
correspond to the default CRUD functionality you can add
additional routes for those methods.
Router::connect(
"/:controller/:id",
array("action" => ”custom_action", "[method]" => "PUT"),
array("id" => "[0-9]+")
);
Specifying HTTP methods
CakePHP's Router class uses a number of different indicators to detect the
HTTP method being used. Here they are in order of preference:
The _method POST variable
The X_HTTP_METHOD_OVERRIDE
The REQUEST_METHOD header
The _method POST variable is helpful in using a browser as a REST client (or
anything else that can do POST easily). Just set the value of _method to
the name of the HTTP request method you wish to emulate.
Setting up views for
additional content types
CakePHP knows when using Router::parseExtensions() to look for content
types in a child directory named after the content type.
/views/[object]/[content type]/[action].ctp
If we want to create an index action for our recipe controller with a content
type of json we would create the following file:
/views/recipes/json/index.ctp
Don’t forget to create a default layout for the content type as well.
/views/layouts/[content type]/default.ctp
Consuming RESTful APIs
with CakePHP
CakePHP’s build in HttpSocket class works great for
consuming RESTful APIs and it’s easy to use!
http://book.cakephp.org/view/1517/HttpSocket
http://api.cakephp.org/class/http-socket
Neil Crookes released an Oauth extension to Cake’s built
in HttpSocket.
http://www.neilcrookes.com/2010/04/12/cakephp-oauth-
extension-to-httpsocket/
CakePHP REST Plugin
Kevin van Zonneveld (kvz) has released and
maintains a REST plugin that features
authentication, rate-limiting per IP, automatic
generation of xml and json views and support for
callback methods.
https://github.com/kvz/cakephp-rest-plugin
The End
Visit my blog http://andrw.net and follow me on twitter
@andruu

Contenu connexe

Tendances

Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Elena Kolevska
 
Codeigniter : Custom Routing - Manipulate Uri
Codeigniter : Custom Routing - Manipulate UriCodeigniter : Custom Routing - Manipulate Uri
Codeigniter : Custom Routing - Manipulate UriAbdul Malik Ikhsan
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101Samantha Geitz
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationAbdul Malik Ikhsan
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST APICaldera Labs
 
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 Connecting Content Silos: One CMS, Many Sites With The WordPress REST API Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Connecting Content Silos: One CMS, Many Sites With The WordPress REST APICaldera Labs
 
An introduction to Laravel Passport
An introduction to Laravel PassportAn introduction to Laravel Passport
An introduction to Laravel PassportMichael Peacock
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface pptTaha Malampatti
 
ACL in CodeIgniter
ACL in CodeIgniterACL in CodeIgniter
ACL in CodeIgnitermirahman
 
RESTful Web Services in Drupal7
RESTful Web Services in Drupal7RESTful Web Services in Drupal7
RESTful Web Services in Drupal7bmeme
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Sumy PHP User Grpoup
 
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Nguyen Duc Phu
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroChristopher Pecoraro
 

Tendances (20)

Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
Codeigniter : Custom Routing - Manipulate Uri
Codeigniter : Custom Routing - Manipulate UriCodeigniter : Custom Routing - Manipulate Uri
Codeigniter : Custom Routing - Manipulate Uri
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept Implementation
 
REST API Laravel
REST API LaravelREST API Laravel
REST API Laravel
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
 
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 Connecting Content Silos: One CMS, Many Sites With The WordPress REST API Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 
Rail3 intro 29th_sep_surendran
Rail3 intro 29th_sep_surendranRail3 intro 29th_sep_surendran
Rail3 intro 29th_sep_surendran
 
An introduction to Laravel Passport
An introduction to Laravel PassportAn introduction to Laravel Passport
An introduction to Laravel Passport
 
Javascript laravel's friend
Javascript laravel's friendJavascript laravel's friend
Javascript laravel's friend
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface ppt
 
Slim Framework
Slim FrameworkSlim Framework
Slim Framework
 
ACL in CodeIgniter
ACL in CodeIgniterACL in CodeIgniter
ACL in CodeIgniter
 
RESTful Web Services in Drupal7
RESTful Web Services in Drupal7RESTful Web Services in Drupal7
RESTful Web Services in Drupal7
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Web api
Web apiWeb api
Web api
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2
 
Psr-7
Psr-7Psr-7
Psr-7
 
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
 

En vedette

9 Awesome cake php tutorials and resources
9 Awesome cake php tutorials and resources9 Awesome cake php tutorials and resources
9 Awesome cake php tutorials and resourcesiScripts
 
Criando e consumindo Web Services (REST) com o CakePHP
Criando e consumindo Web Services (REST) com o CakePHPCriando e consumindo Web Services (REST) com o CakePHP
Criando e consumindo Web Services (REST) com o CakePHP2km interativa!
 
Writing RESTful Web Services
Writing RESTful Web ServicesWriting RESTful Web Services
Writing RESTful Web ServicesPaul Boocock
 
CakePHP 2.0 - It'll rock your world
CakePHP 2.0 - It'll rock your worldCakePHP 2.0 - It'll rock your world
CakePHP 2.0 - It'll rock your worldGraham Weldon
 
With jQuery & CakePHP to World Domination
With jQuery & CakePHP to World DominationWith jQuery & CakePHP to World Domination
With jQuery & CakePHP to World DominationFelix Geisendörfer
 
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
 
CakePHP Community Keynote 2014
CakePHP Community Keynote 2014CakePHP Community Keynote 2014
CakePHP Community Keynote 2014James Watts
 
CakePHP mistakes made
CakePHP mistakes madeCakePHP mistakes made
CakePHP mistakes mademarkstory
 
Customize CakePHP bake
Customize CakePHP bakeCustomize CakePHP bake
Customize CakePHP bakeKazuyuki Aoki
 
Recursive in CakePHP
Recursive in CakePHPRecursive in CakePHP
Recursive in CakePHPKetan Patel
 

En vedette (20)

9 Awesome cake php tutorials and resources
9 Awesome cake php tutorials and resources9 Awesome cake php tutorials and resources
9 Awesome cake php tutorials and resources
 
Agile database access with CakePHP 3
Agile database access with CakePHP 3Agile database access with CakePHP 3
Agile database access with CakePHP 3
 
Full-Stack CakePHP Deployment
Full-Stack CakePHP DeploymentFull-Stack CakePHP Deployment
Full-Stack CakePHP Deployment
 
Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3
 
Criando e consumindo Web Services (REST) com o CakePHP
Criando e consumindo Web Services (REST) com o CakePHPCriando e consumindo Web Services (REST) com o CakePHP
Criando e consumindo Web Services (REST) com o CakePHP
 
Cakephp 3
Cakephp 3 Cakephp 3
Cakephp 3
 
CakePHP
CakePHPCakePHP
CakePHP
 
PPT - A slice of cake php
PPT - A slice of cake phpPPT - A slice of cake php
PPT - A slice of cake php
 
Cakephp
CakephpCakephp
Cakephp
 
Introduction to CakePHP
Introduction to CakePHPIntroduction to CakePHP
Introduction to CakePHP
 
Writing RESTful Web Services
Writing RESTful Web ServicesWriting RESTful Web Services
Writing RESTful Web Services
 
CakePHP 2.0 - It'll rock your world
CakePHP 2.0 - It'll rock your worldCakePHP 2.0 - It'll rock your world
CakePHP 2.0 - It'll rock your world
 
With jQuery & CakePHP to World Domination
With jQuery & CakePHP to World DominationWith jQuery & CakePHP to World Domination
With jQuery & CakePHP to World Domination
 
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
 
CakePHP Community Keynote 2014
CakePHP Community Keynote 2014CakePHP Community Keynote 2014
CakePHP Community Keynote 2014
 
CakePHP
CakePHPCakePHP
CakePHP
 
Why MariaDB?
Why MariaDB?Why MariaDB?
Why MariaDB?
 
CakePHP mistakes made
CakePHP mistakes madeCakePHP mistakes made
CakePHP mistakes made
 
Customize CakePHP bake
Customize CakePHP bakeCustomize CakePHP bake
Customize CakePHP bake
 
Recursive in CakePHP
Recursive in CakePHPRecursive in CakePHP
Recursive in CakePHP
 

Similaire à RESTful Web Development with CakePHP

ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiTiago Knoch
 
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!Evan Mullins
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsIdo Flatow
 
Share point – client search api’s
Share point – client search api’sShare point – client search api’s
Share point – client search api’sMikael Svenson
 
Best practices and advantages of REST APIs
Best practices and advantages of REST APIsBest practices and advantages of REST APIs
Best practices and advantages of REST APIsAparna Sharma
 
Rest service in mule
Rest service in mule Rest service in mule
Rest service in mule Harish43
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1vikram singh
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technologyvikram singh
 
SPFx Webinar Loading SharePoint data in a SPFx Webpart
SPFx Webinar Loading SharePoint data in a SPFx WebpartSPFx Webinar Loading SharePoint data in a SPFx Webpart
SPFx Webinar Loading SharePoint data in a SPFx WebpartJenkins NS
 
Creating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew TurlandCreating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew TurlandMatthew Turland
 
RestFul Web Services In Drupal 8
RestFul Web Services In Drupal 8RestFul Web Services In Drupal 8
RestFul Web Services In Drupal 8Gajendra Sharma
 
Rest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbookRest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbookKaty Slemon
 
RESTful application with Drupal 8
RESTful application with Drupal 8RESTful application with Drupal 8
RESTful application with Drupal 8Patrick Morin
 

Similaire à RESTful Web Development with CakePHP (20)

ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
Implementation web api
Implementation web apiImplementation web api
Implementation web api
 
Standards of rest api
Standards of rest apiStandards of rest api
Standards of rest api
 
REST full API Design
REST full API DesignREST full API Design
REST full API Design
 
11 asp.net web api
11 asp.net web api11 asp.net web api
11 asp.net web api
 
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP Fundamentals
 
Share point – client search api’s
Share point – client search api’sShare point – client search api’s
Share point – client search api’s
 
Best practices and advantages of REST APIs
Best practices and advantages of REST APIsBest practices and advantages of REST APIs
Best practices and advantages of REST APIs
 
Rest service in mule
Rest service in mule Rest service in mule
Rest service in mule
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
 
SPFx Webinar Loading SharePoint data in a SPFx Webpart
SPFx Webinar Loading SharePoint data in a SPFx WebpartSPFx Webinar Loading SharePoint data in a SPFx Webpart
SPFx Webinar Loading SharePoint data in a SPFx Webpart
 
Rest Service In Mule
Rest Service In Mule Rest Service In Mule
Rest Service In Mule
 
Creating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew TurlandCreating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew Turland
 
RestFul Web Services In Drupal 8
RestFul Web Services In Drupal 8RestFul Web Services In Drupal 8
RestFul Web Services In Drupal 8
 
Rest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbookRest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbook
 
RESTful application with Drupal 8
RESTful application with Drupal 8RESTful application with Drupal 8
RESTful application with Drupal 8
 
Web API with ASP.NET MVC by Software development company in india
Web API with ASP.NET  MVC  by Software development company in indiaWeb API with ASP.NET  MVC  by Software development company in india
Web API with ASP.NET MVC by Software development company in india
 

Dernier

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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 Processorsdebabhi2
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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...Drew Madelung
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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?Antenna Manufacturer Coco
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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 AutomationSafe Software
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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 WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Dernier (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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?
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

RESTful Web Development with CakePHP

  • 1.
  • 2. What is REST? REST (Representational State Transfer) is a style of software architecture mainly used for web services to communicate between servers and clients using existing features of the HTTP protocol. The main HTTP verbs/methods used in REST are GET, POST, PUT and DELETE http://en.wikipedia.org/wiki/REST
  • 3. Most companies online who offer APIs and webservices use REST. Who’s using REST?
  • 4. Why use REST? You’ve already wrote the code! Use your existing code with little changes. Open your application to the public. Allow other developers to integrate your application into their projects or extend the functionality of your application. Create applications on multiple platforms. Using your REST API you can build mobile and desktop applications using your existing code base.
  • 5. REST in CakePHP REST in CakePHP is simple. Add RESTful controllers to Router::mapResources() to set up default routes in /config/router.php. Add desired extensions to Router::parseExtension() eg. xml, json, yaml, etc. in /config/router.php. Add RequestHandler component to controllers with REST functionality. http://book.cakephp.org/view/1238/REST
  • 6. CakePHP RESTful routing HTTP Method URL Controller Action GET /recipes.ext RecipesController::index() GET /recipes/123.ext RecipesController::view(123) POST /recipes.ext RecipesController::add() PUT /recipes/123.ext RecipesController::edit(123) DELETE /recipes/123.ext RecipesController::delete(123) POST /recipes/123.ext RecipesController::edit(123)
  • 7. Custom RESTful routing If you have additional methods in your controller that don’t correspond to the default CRUD functionality you can add additional routes for those methods. Router::connect( "/:controller/:id", array("action" => ”custom_action", "[method]" => "PUT"), array("id" => "[0-9]+") );
  • 8. Specifying HTTP methods CakePHP's Router class uses a number of different indicators to detect the HTTP method being used. Here they are in order of preference: The _method POST variable The X_HTTP_METHOD_OVERRIDE The REQUEST_METHOD header The _method POST variable is helpful in using a browser as a REST client (or anything else that can do POST easily). Just set the value of _method to the name of the HTTP request method you wish to emulate.
  • 9. Setting up views for additional content types CakePHP knows when using Router::parseExtensions() to look for content types in a child directory named after the content type. /views/[object]/[content type]/[action].ctp If we want to create an index action for our recipe controller with a content type of json we would create the following file: /views/recipes/json/index.ctp Don’t forget to create a default layout for the content type as well. /views/layouts/[content type]/default.ctp
  • 10. Consuming RESTful APIs with CakePHP CakePHP’s build in HttpSocket class works great for consuming RESTful APIs and it’s easy to use! http://book.cakephp.org/view/1517/HttpSocket http://api.cakephp.org/class/http-socket Neil Crookes released an Oauth extension to Cake’s built in HttpSocket. http://www.neilcrookes.com/2010/04/12/cakephp-oauth- extension-to-httpsocket/
  • 11. CakePHP REST Plugin Kevin van Zonneveld (kvz) has released and maintains a REST plugin that features authentication, rate-limiting per IP, automatic generation of xml and json views and support for callback methods. https://github.com/kvz/cakephp-rest-plugin
  • 12. The End Visit my blog http://andrw.net and follow me on twitter @andruu