SlideShare a Scribd company logo
Who
Who
    Kevin van Zonneveld
        t: @kvz          e: kvz@php.net


•   Developer, trapped in a sysadmin’s body

•   company: Hosting provider specialized in
    scalability: http://true.nl

•   cake: Learned from Felix while working on
    http://phpjs.org

•   likes: Reusable code & to Automate everything.
What
What




CakePHP REST Plugin
  Does heavy lifting so you can finally rest.
What
             Design Goals

• Painless drop-in
  Should not bite existing code


• Use existing controller actions
  Just add .json to your URLs and REST kicks in.


• Declarative configuration
  Inject viewVars according to Set::extract()-compatible source & destination
  paths
Why
Why

                REST helps..
• Open up your application
  Let others write the features you don’t have the time for, couldn’t be
  bothered with, or even imagine.
  Bottom line: your product is getting used more, while you are doing less.


• Close down your application
  By making use of existing authentication & authorization code in your app,
  you can restrict anyone from anything.


• Reuse your application
  Let your own little scripts - running on different servers - use the API as
  well. They won’t need database access, and existing Model / caching / logging
  logic will be used at all times.
Why

     What I use it for
• Distributing config files throughout our
  network
• Letting customers edit DNS records,
  reboot servers, through their own interface
• Receiving monitoring status reports and
  updating them through our Cake Models
• Letting customers retrieve statistic
• All bots have their own API-key. Raw
  MySQL connections no longer allowed
How
How

                                 Features
                                       Already implemented


• Logging & Rate-limiting
  Configurable max requests per type of authenticated user.


• Can dump all RESTful controllers
  So your client API can iterate & instantiate them, and make the following
  simple syntax available:
  $Api->Servers->index();
  $Api->Servers->edit(2, array(‘hostname’ => ‘awesome.true.nl’));




• Minimal changes
  ..to your existing Cake App


• Authentication
  Uses the Authorization header just like Amazon S3; have your client set it
  with every request (remember, REST is stateless):
  Authorization: TRUEREST username=john&password=xxx&apikey=247b5a2f72df375279573f2746686daa

  http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTAuthentication.html
How

             Setup files
• Save it to a ‘rest’ directory inside your
  plugins folder.
How

         Setup router

• Makes sure .json files are parsed by Cake
• Maps the controllers you want to open up
How

           Setup controllers
•   You already have a working view & index method

•   Rest Plugin can reuse any of their viewVars

•   Optionally transform them them into different arrangements so you can talk
    in a consistent format to you clients.
    In this case, servers are always presented as:
    servers: {
        0: {
             hostname:   “awesome.true.nl”
        }
    }


    even if it’s just
    one.
How

            Reroute errors

• Use one AppController::_flash() method
  From now on, forward all your: ‘No access’, Error & Success messages to
  this method. Let it call setFlash() as you would normally.


• And let it check if REST is active:
        if ($this->_isRest()) {
            // map CSS flash error levels to corresponding rest methods.
            $map = array(
                'failure' => 'error',
                'neutral' => 'info',
                'success' => 'info',
            );
            $func = $map[$type];

            return $this->Rest->{$func}($str);
        }




• REST plugin will take care of the rest ; )
How
 Setup authentication
                                Optional

• Retrieve REST credentials & login
  public function beforeFilter() {
      $credentials = $this->Rest->credentials();
      // Hash them with Security::salt

      $success = $this->Auth->login($credentials);
      // Further handling of return value
  }




• Done!
  The REST client has logged in as an actual user (or not), and from here-on,
  it’s your app’s domain, just like you’re used to. This means whatever ACL or
  other authorization code you have in place, will be respected.
How

                            Todo
• XML
  For now only .json is supported


• Testing
  Expose to more programmers & environments to track issues.
  Unit tests


• HMAC Signed requests
  Could provide additional security (even though you’re probably not doing
  this with regular https requests either, and you are only opening up existing
  functionality, so I consider it secure enough to use over HTTPS as it is)


• IP-based rate-limiter
  Better protection against DDOS attacks than the current api-key based.
Where
Where

                     Here:
•   Fork
    http://github.com/kvz/cakephp-rest-plugin

•   Follow
    http://twitter.com/kvz

•   Subscribe
    http://kevin.vanzonneveld.net

•   Mail
    kvz@php.net

•   Check
    http://true.nl
Questions?
Thank you!

More Related Content

PPTX
CakeFest 2013 - A-Z REST APIs
PPTX
Designing CakePHP plugins for consuming APIs
PPTX
RESTful Web Development with CakePHP
PPTX
Web api
PDF
Cake fest 2012 create a restful api
PDF
REST API with CakePHP
PPTX
40+ tips to use Postman more efficiently
PDF
ACL in CodeIgniter
CakeFest 2013 - A-Z REST APIs
Designing CakePHP plugins for consuming APIs
RESTful Web Development with CakePHP
Web api
Cake fest 2012 create a restful api
REST API with CakePHP
40+ tips to use Postman more efficiently
ACL in CodeIgniter

What's hot (20)

PDF
Building RESTful applications using Spring MVC
PDF
Understanding and testing restful web services
PPTX
REST APIs in Laravel 101
PDF
RESTful API development in Laravel 4 - Christopher Pecoraro
PPTX
Slim Framework
PPT
Web service with Laravel
ODP
Javascript laravel's friend
PPTX
Postman Collection Format v2.0 (pre-draft)
PPTX
API Development with Laravel
PDF
4 introduction-php-mvc-cakephp-m4-controllers-slides
PDF
Web services with laravel
PPTX
PPTX
Introduction to laravel framework
PDF
Spring Mvc Rest
PPTX
REST API Best Practices & Implementing in Codeigniter
PDF
Laravel Restful API and AngularJS
ODP
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
PPTX
Test automation of ap is using postman
ODP
Burlington, VT PHP Users Group Subversion Presentation
PDF
Building a Backend with Flask
Building RESTful applications using Spring MVC
Understanding and testing restful web services
REST APIs in Laravel 101
RESTful API development in Laravel 4 - Christopher Pecoraro
Slim Framework
Web service with Laravel
Javascript laravel's friend
Postman Collection Format v2.0 (pre-draft)
API Development with Laravel
4 introduction-php-mvc-cakephp-m4-controllers-slides
Web services with laravel
Introduction to laravel framework
Spring Mvc Rest
REST API Best Practices & Implementing in Codeigniter
Laravel Restful API and AngularJS
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Test automation of ap is using postman
Burlington, VT PHP Users Group Subversion Presentation
Building a Backend with Flask
Ad

Similar to CakePHP REST Plugin (20)

PDF
Designing your API Server for mobile apps
PDF
Extending WordPress as a pro
PDF
Chef for openstack
PDF
Introduction to Infrastructure as Code & Automation / Introduction to Chef
PPTX
.NET microservices with Azure Service Fabric
PPTX
Chef for Openstack
PDF
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
PPTX
Opscode Webinar: Managing Your VMware Infrastructure with Chef
PDF
Serverless: A love hate relationship
PPTX
REST API 20.2 - Appworks Gateway Integration.pptx
PDF
Web Services Tutorial
PDF
Google App Engine
PDF
Overview of Chef - Fundamentals Webinar Series Part 1
PDF
Apigility-powered API's on IBM i
PPTX
DDD Melbourne 2014 security in ASP.Net Web API 2
PDF
Making the most out of CakePHP 2.2
PPTX
App fabric introduction
PDF
JavaScript Service Worker Design Patterns for Better User Experience
PPTX
Understand Chef
PDF
DOO-009_Powering High Velocity Development for your Infrastructure
Designing your API Server for mobile apps
Extending WordPress as a pro
Chef for openstack
Introduction to Infrastructure as Code & Automation / Introduction to Chef
.NET microservices with Azure Service Fabric
Chef for Openstack
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Opscode Webinar: Managing Your VMware Infrastructure with Chef
Serverless: A love hate relationship
REST API 20.2 - Appworks Gateway Integration.pptx
Web Services Tutorial
Google App Engine
Overview of Chef - Fundamentals Webinar Series Part 1
Apigility-powered API's on IBM i
DDD Melbourne 2014 security in ASP.Net Web API 2
Making the most out of CakePHP 2.2
App fabric introduction
JavaScript Service Worker Design Patterns for Better User Experience
Understand Chef
DOO-009_Powering High Velocity Development for your Infrastructure
Ad

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Modernizing your data center with Dell and AMD
PDF
Empathic Computing: Creating Shared Understanding
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
cuic standard and advanced reporting.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Chapter 3 Spatial Domain Image Processing.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Review of recent advances in non-invasive hemoglobin estimation
NewMind AI Weekly Chronicles - August'25 Week I
Agricultural_Statistics_at_a_Glance_2022_0.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Dropbox Q2 2025 Financial Results & Investor Presentation
Modernizing your data center with Dell and AMD
Empathic Computing: Creating Shared Understanding
Advanced methodologies resolving dimensionality complications for autism neur...
Mobile App Security Testing_ A Comprehensive Guide.pdf

CakePHP REST Plugin

  • 1. Who
  • 2. Who Kevin van Zonneveld t: @kvz e: kvz@php.net • Developer, trapped in a sysadmin’s body • company: Hosting provider specialized in scalability: http://true.nl • cake: Learned from Felix while working on http://phpjs.org • likes: Reusable code & to Automate everything.
  • 4. What CakePHP REST Plugin Does heavy lifting so you can finally rest.
  • 5. What Design Goals • Painless drop-in Should not bite existing code • Use existing controller actions Just add .json to your URLs and REST kicks in. • Declarative configuration Inject viewVars according to Set::extract()-compatible source & destination paths
  • 6. Why
  • 7. Why REST helps.. • Open up your application Let others write the features you don’t have the time for, couldn’t be bothered with, or even imagine. Bottom line: your product is getting used more, while you are doing less. • Close down your application By making use of existing authentication & authorization code in your app, you can restrict anyone from anything. • Reuse your application Let your own little scripts - running on different servers - use the API as well. They won’t need database access, and existing Model / caching / logging logic will be used at all times.
  • 8. Why What I use it for • Distributing config files throughout our network • Letting customers edit DNS records, reboot servers, through their own interface • Receiving monitoring status reports and updating them through our Cake Models • Letting customers retrieve statistic • All bots have their own API-key. Raw MySQL connections no longer allowed
  • 9. How
  • 10. How Features Already implemented • Logging & Rate-limiting Configurable max requests per type of authenticated user. • Can dump all RESTful controllers So your client API can iterate & instantiate them, and make the following simple syntax available: $Api->Servers->index(); $Api->Servers->edit(2, array(‘hostname’ => ‘awesome.true.nl’)); • Minimal changes ..to your existing Cake App • Authentication Uses the Authorization header just like Amazon S3; have your client set it with every request (remember, REST is stateless): Authorization: TRUEREST username=john&password=xxx&apikey=247b5a2f72df375279573f2746686daa http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTAuthentication.html
  • 11. How Setup files • Save it to a ‘rest’ directory inside your plugins folder.
  • 12. How Setup router • Makes sure .json files are parsed by Cake • Maps the controllers you want to open up
  • 13. How Setup controllers • You already have a working view & index method • Rest Plugin can reuse any of their viewVars • Optionally transform them them into different arrangements so you can talk in a consistent format to you clients. In this case, servers are always presented as: servers: { 0: { hostname: “awesome.true.nl” } } even if it’s just one.
  • 14. How Reroute errors • Use one AppController::_flash() method From now on, forward all your: ‘No access’, Error & Success messages to this method. Let it call setFlash() as you would normally. • And let it check if REST is active: if ($this->_isRest()) { // map CSS flash error levels to corresponding rest methods. $map = array( 'failure' => 'error', 'neutral' => 'info', 'success' => 'info', ); $func = $map[$type]; return $this->Rest->{$func}($str); } • REST plugin will take care of the rest ; )
  • 15. How Setup authentication Optional • Retrieve REST credentials & login public function beforeFilter() { $credentials = $this->Rest->credentials(); // Hash them with Security::salt $success = $this->Auth->login($credentials); // Further handling of return value } • Done! The REST client has logged in as an actual user (or not), and from here-on, it’s your app’s domain, just like you’re used to. This means whatever ACL or other authorization code you have in place, will be respected.
  • 16. How Todo • XML For now only .json is supported • Testing Expose to more programmers & environments to track issues. Unit tests • HMAC Signed requests Could provide additional security (even though you’re probably not doing this with regular https requests either, and you are only opening up existing functionality, so I consider it secure enough to use over HTTPS as it is) • IP-based rate-limiter Better protection against DDOS attacks than the current api-key based.
  • 17. Where
  • 18. Where Here: • Fork http://github.com/kvz/cakephp-rest-plugin • Follow http://twitter.com/kvz • Subscribe http://kevin.vanzonneveld.net • Mail kvz@php.net • Check http://true.nl