SlideShare a Scribd company logo
1 of 43
API Development Becoming the Platform (CakePHP for Back-End Development or Cake for Web Services) By Andrew Curioso CakeFest 2010
Introduction Yesterday:  Designing CakePHP plug-ins for consuming APIs Today: Create your own API Basic setup Extras
Become a platform Be โ€œaโ€ platform A blog is a platform
Become a platform Internal only (closed) Multi-platform (consumers) Scalable External (open) Everything + Growth Mash-ups! Innovation Evangelists โ€œThe Platform Playโ€
Whoโ€™s already a platform Google Facebook Digg Twitter Yahoo BOSS / Flickr / Delicious / etc. Salesforce Ebay Amazon Gowalla FourSquare Bit.ly Paypal Authorize.net Etcโ€ฆ
Types of APIs Patterns Representation State Transfer (REST) Remote Procedure Calls (RPC) Protocols / Formats XML JSON YAML  AMF Etc...
RESTful Representational State Transfer Resource based (nouns) 5 verbs GET PUT POST DELETE HEAD Easy in CakePHP
Todayโ€™s App URL shortening website User authentication (simple) Create, read, update, and delete (CRUD)
Models id user_id url created modified users urls
Making it RESTful APP/config/routes.php Router::mapResource(โ€˜usersโ€™) Source: http://book.cakephp.org/view/1239/The-Simple-Setup
Security Pitfall ,[object Object],Only POST and PUT should write data Only POST and DELETE should delete data
Mapping Extensions Router::parseExtensions() RequestHandler component Switches layouts / views Includes helpers Parses incoming XML on POST Router::connect(      "/:controller/:idโ€,     array ("action" => "edit", "[method]" => "PUT"), array("id" => "[0-9]+โ€) ); Source: http://book.cakephp.org/view/1240/Custom-REST-Routing
Json View Simple Fast Wide-spread <?php     echo json_encode( $url ); ?> APP/views/urls/json/view.ctp
JsonP P ๏ƒจw/ padding Uses callback Cross domain <?php     if ( $callbackFunc !== false )         echo $callbackFunc.'(';     echo $content_for_layout;     if ( $callbackFunc )         echo $callbackFunc.')';    ?> function beforeFilter() {     if ( array_key_exists('callbackโ€™, $this->params[โ€˜urlโ€™]) )         $this->set(โ€˜callbackFuncโ€™, $this->params[โ€˜urlโ€™][โ€˜callbackโ€™]);     else         $this->set(โ€˜callbackFuncโ€™, false); } APP/views/layouts/json/default.ctp APP/app_controller.php
XML View Strongly Typed Human readable Lots of existing tools <?   echo โ€˜<url>โ€™;   echo $xml->serialize( $url );   echo โ€˜<url>โ€™; ?> APP/views/urls/xml/view.ctp
Other Views Human Readable XML Json / JsonP HTML YAML CSV Serialized PHP Etcโ€ฆ Binary AMF Microsoft Excel PDF JPEG / PNG Etcโ€ฆ
Testing It Out Using cURL Create curl โ€“d โ€œurl=www.example.comโ€ http://tinyr.me/urls.json Read curl http://tinyr.me/urls/123.json Update curl โ€“d โ€œurl=www.example.com/fooโ€ http://tinyr.me/urls/123.json Delete curl โ€“X DELETE http://tinyr.me/urls/123.json
Done? We have MVC files RESTful Views XML Json / JsonP Weโ€™re missing Error handling Pagination Authentication Authorization Documentation
Status Codes Success 200 OK * 201 Created * 303 See Other * Error 401 Unauthorized * 402 Payment Required 403 Forbidden * 404 Not Found * Error (continued) 405 Method Not Allowed * 409 Conflict 410 Gone 500 Internal Server Error 501 Not Implemented 503 Service Unavailable
Add Method If not a POST request 405 Method Not Allowed Already existed 303 See Other Save success 201 Created Failure  200 OK with explanation
Edit Method If not a POST or PUT request 405 Method Not Allowed Invalid ID 404 File Not Found Success 200 OK Failure 200 OK with explanation
Delete Method If not a POST or DELETE request 405 Method Not Allowed Invalid ID 404 File Not Found Success 200 OK Failure 200 OK with explanation
Global User is not allowed to access resource 403 Forbidden  User is not logged in 401 Unauthorized
Throwing Errors Same format Descriptive Human Computer Comprehensive
Implementation function your_action() {   โ€ฆ   $this->_userError(404);   โ€ฆ } APP/controllers/your_controller.php function _userError( $code, $options=array() ) {   $codes = array(     402 => 'Payment Required',     โ€ฆ   );   $this->header("HTTP/1.1 {$type} {$codes[$type]}");   $this->cakeError('error'.$type, array( array( 'options' => $options ) ) ); } APP/app_controller.php
Implementation {"Error": {   "code" : 404,   "description" : "File Not Found" }} APP/views/errors/error404.ctp
HTTP Headers Return meta-information Rate limiting Pagination Etc.
Pagination Uses HTTP headers App defined start with โ€œX-โ€ function paginate($object=NULL, $scope=array(), $whitelist=array() ) {     $data = parent::paginate($object,$scope,$whitelist);     // โ€ฆ messy code to get the object โ€ฆ     $this->header('X-Current-Page: '.((int)$this->params['paging'][$object->alias]['page']));     $this->header('X-Page-Limit: '.((int)$this->params['paging'][$object->alias]['options']['limit']));     $this->header('X-Page-Total: '.((int)$this->params['paging'][$object->alias]['count']));     return $data; } APP/app_controller.php
Multi-Platform Dev Use a UI that makes sense Bring something to the table
Platform Support Web Browsers Do not support: DELETE PUT Fortunately Cakeโ€ฆ Letโ€™s you do this: _method=DELETE
Platform Support DELETE /urls/123.json HTTP1.1 Host: www.example.com POST /urls/123.json HTTP1.1 Host: www.example.com _method=DELETE
Authentication
Authorization There is no magic One or more: user_id Administrator Moderator
Documentation Vocabularies / Schemas DTD or schema files Examples Code I/O Community Feedback
What about SOAP and AMF? CakePHP rocks with REST SOAP is heavy AMF is light but requires Flash But, if you still want to, you can
Flow for SOAP and AMF
Example Flow Router UrlsController AmfController User POST ::gateway() ::view() Return data Format envelope
Some final wordsโ€ฆ
Donโ€™t Choose Views are easy
API Developers Checklist Documentation Example code Definition files (if applicable) Unit tests
Finding the code MIT License http://tinyr.me
Happy Aniversary Happy anniversary, Laura. 1 year: Sept. 5, 2010
Andrew Curioso Contact: www.AndrewCurioso.com/contact @AndrewCurioso on Twitter

More Related Content

What's hot

Using PHP
Using PHPUsing PHP
Using PHPMark Casias
ย 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPwahidullah mudaser
ย 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQLkalaisai
ย 
Secure PHP Coding - Part 1
Secure PHP Coding - Part 1Secure PHP Coding - Part 1
Secure PHP Coding - Part 1Vinoth Kumar
ย 
Secure PHP Coding - Part 2
Secure PHP Coding - Part 2Secure PHP Coding - Part 2
Secure PHP Coding - Part 2Vinoth Kumar
ย 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHPJussi Pohjolainen
ย 
Make WordPress realtime.
Make WordPress realtime.Make WordPress realtime.
Make WordPress realtime.Josh Hillier
ย 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture NotesSanthiya Grace
ย 
Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Ajay Khatri
ย 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionMazenetsolution
ย 
Flask patterns
Flask patternsFlask patterns
Flask patternsit-people
ย 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop NotesPamela Fox
ย 
Playing nice with others
Playing nice with othersPlaying nice with others
Playing nice with othersEric Mann
ย 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQLJussi Pohjolainen
ย 
Php Calling Operators
Php Calling OperatorsPhp Calling Operators
Php Calling Operatorsmussawir20
ย 
Oracle APEX Performance
Oracle APEX PerformanceOracle APEX Performance
Oracle APEX PerformanceScott Wesley
ย 
Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2RORLAB
ย 

What's hot (20)

Using PHP
Using PHPUsing PHP
Using PHP
ย 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
ย 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
ย 
Secure PHP Coding - Part 1
Secure PHP Coding - Part 1Secure PHP Coding - Part 1
Secure PHP Coding - Part 1
ย 
Secure PHP Coding - Part 2
Secure PHP Coding - Part 2Secure PHP Coding - Part 2
Secure PHP Coding - Part 2
ย 
Php mysql
Php mysqlPhp mysql
Php mysql
ย 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
ย 
Make WordPress realtime.
Make WordPress realtime.Make WordPress realtime.
Make WordPress realtime.
ย 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
ย 
PHP
PHP PHP
PHP
ย 
Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Introduction to PHP Lecture 1
Introduction to PHP Lecture 1
ย 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
ย 
Flask patterns
Flask patternsFlask patterns
Flask patterns
ย 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
ย 
Playing nice with others
Playing nice with othersPlaying nice with others
Playing nice with others
ย 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
ย 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
ย 
Php Calling Operators
Php Calling OperatorsPhp Calling Operators
Php Calling Operators
ย 
Oracle APEX Performance
Oracle APEX PerformanceOracle APEX Performance
Oracle APEX Performance
ย 
Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2
ย 

Similar to Cakefest 2010: API Development

PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
ย 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHPMatthew Turland
ย 
State Machines to State of the Art
State Machines to State of the ArtState Machines to State of the Art
State Machines to State of the ArtRowan Merewood
ย 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswanivvaswani
ย 
Framework
FrameworkFramework
FrameworkNguyen Linh
ย 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
ย 
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Michael Wales
ย 
The Django Web Application Framework
The Django Web Application FrameworkThe Django Web Application Framework
The Django Web Application FrameworkSimon Willison
ย 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHPMatthew Turland
ย 
Php security3895
Php security3895Php security3895
Php security3895PrinceGuru MS
ย 
PHP Security
PHP SecurityPHP Security
PHP Securitymanugoel2003
ย 
Php Security3895
Php Security3895Php Security3895
Php Security3895Aung Khant
ย 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Elena Kolevska
ย 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkDirk Haun
ย 
Implementing Comet using PHP
Implementing Comet using PHPImplementing Comet using PHP
Implementing Comet using PHPKing Foo
ย 
Ellerslie User Group - ReST Presentation
Ellerslie User Group - ReST PresentationEllerslie User Group - ReST Presentation
Ellerslie User Group - ReST PresentationAlex Henderson
ย 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHPMatthew Turland
ย 

Similar to Cakefest 2010: API Development (20)

PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
ย 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
ย 
State Machines to State of the Art
State Machines to State of the ArtState Machines to State of the Art
State Machines to State of the Art
ย 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
ย 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
ย 
Framework
FrameworkFramework
Framework
ย 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
ย 
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
ย 
Php frameworks
Php frameworksPhp frameworks
Php frameworks
ย 
The Django Web Application Framework
The Django Web Application FrameworkThe Django Web Application Framework
The Django Web Application Framework
ย 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
ย 
Php security3895
Php security3895Php security3895
Php security3895
ย 
PHP Security
PHP SecurityPHP Security
PHP Security
ย 
B03-GenomeContent-Intermine
B03-GenomeContent-IntermineB03-GenomeContent-Intermine
B03-GenomeContent-Intermine
ย 
Php Security3895
Php Security3895Php Security3895
Php Security3895
ย 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
ย 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
ย 
Implementing Comet using PHP
Implementing Comet using PHPImplementing Comet using PHP
Implementing Comet using PHP
ย 
Ellerslie User Group - ReST Presentation
Ellerslie User Group - ReST PresentationEllerslie User Group - ReST Presentation
Ellerslie User Group - ReST Presentation
ย 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
ย 

Recently uploaded

Beautiful ๐Ÿ˜‹ Call girls in Lahore 03210033448
Beautiful ๐Ÿ˜‹ Call girls in Lahore 03210033448Beautiful ๐Ÿ˜‹ Call girls in Lahore 03210033448
Beautiful ๐Ÿ˜‹ Call girls in Lahore 03210033448ont65320
ย 
Goa Call Girls 9316020077 Call Girls In Goa By Russian Call Girl in goa
Goa Call Girls 9316020077 Call Girls  In Goa By Russian Call Girl in goaGoa Call Girls 9316020077 Call Girls  In Goa By Russian Call Girl in goa
Goa Call Girls 9316020077 Call Girls In Goa By Russian Call Girl in goarussian goa call girl and escorts service
ย 
๐“€คCall On 6297143586 ๐“€ค Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...
๐“€คCall On 6297143586 ๐“€ค Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...๐“€คCall On 6297143586 ๐“€ค Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...
๐“€คCall On 6297143586 ๐“€ค Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...rahim quresi
ย 
Independent Hatiara Escorts โœ” 9332606886โœ” Full Night With Room Online Booking...
Independent Hatiara Escorts โœ” 9332606886โœ” Full Night With Room Online Booking...Independent Hatiara Escorts โœ” 9332606886โœ” Full Night With Room Online Booking...
Independent Hatiara Escorts โœ” 9332606886โœ” Full Night With Room Online Booking...Riya Pathan
ย 
5* Hotels Call Girls In Goa {{07028418221}} Call Girls In North Goa Escort Se...
5* Hotels Call Girls In Goa {{07028418221}} Call Girls In North Goa Escort Se...5* Hotels Call Girls In Goa {{07028418221}} Call Girls In North Goa Escort Se...
5* Hotels Call Girls In Goa {{07028418221}} Call Girls In North Goa Escort Se...Apsara Of India
ย 
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24... Shivani Pandey
ย 
๐“€คCall On 6297143586 ๐“€ค Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...
๐“€คCall On 6297143586 ๐“€ค Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...๐“€คCall On 6297143586 ๐“€ค Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...
๐“€คCall On 6297143586 ๐“€ค Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...rahim quresi
ย 
Call Girls Agency In Goa ๐Ÿ’š 9316020077 ๐Ÿ’š Call Girl Goa By Russian Call Girl ...
Call Girls  Agency In Goa  ๐Ÿ’š 9316020077 ๐Ÿ’š Call Girl Goa By Russian Call Girl ...Call Girls  Agency In Goa  ๐Ÿ’š 9316020077 ๐Ÿ’š Call Girl Goa By Russian Call Girl ...
Call Girls Agency In Goa ๐Ÿ’š 9316020077 ๐Ÿ’š Call Girl Goa By Russian Call Girl ...russian goa call girl and escorts service
ย 
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser... Shivani Pandey
ย 
Almora call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment Booking
Almora call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment BookingAlmora call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment Booking
Almora call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment BookingNitya salvi
ย 
Kanpur call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment BookingKanpur call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment BookingNitya salvi
ย 
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...SUHANI PANDEY
ย 
Independent Joka Escorts โœ” 8250192130 โœ” Full Night With Room Online Booking 2...
Independent Joka Escorts โœ” 8250192130 โœ” Full Night With Room Online Booking 2...Independent Joka Escorts โœ” 8250192130 โœ” Full Night With Room Online Booking 2...
Independent Joka Escorts โœ” 8250192130 โœ” Full Night With Room Online Booking 2...noor ahmed
ย 
โคPersonal Whatsapp Number Keylong Call Girls 8617697112 ๐Ÿ’ฆโœ….
โคPersonal Whatsapp Number Keylong Call Girls 8617697112 ๐Ÿ’ฆโœ….โคPersonal Whatsapp Number Keylong Call Girls 8617697112 ๐Ÿ’ฆโœ….
โคPersonal Whatsapp Number Keylong Call Girls 8617697112 ๐Ÿ’ฆโœ….Nitya salvi
ย 
Dakshineswar Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Se...
Dakshineswar Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Se...Dakshineswar Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Se...
Dakshineswar Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Se...aamir
ย 
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser... Shivani Pandey
ย 
Sonagachi ( Call Girls ) Kolkata โœ” 6297143586 โœ” Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata โœ” 6297143586 โœ” Hot Model With Sexy Bhabi Rea...Sonagachi ( Call Girls ) Kolkata โœ” 6297143586 โœ” Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata โœ” 6297143586 โœ” Hot Model With Sexy Bhabi Rea...rahim quresi
ย 
Nayabad Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Sex At ...Nayabad Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Sex At ...aamir
ย 
Bhimtal โคCALL GIRL 8617697112 โคCALL GIRLS IN Bhimtal ESCORT SERVICEโคCALL GIRL
Bhimtal โคCALL GIRL 8617697112 โคCALL GIRLS IN Bhimtal ESCORT SERVICEโคCALL GIRLBhimtal โคCALL GIRL 8617697112 โคCALL GIRLS IN Bhimtal ESCORT SERVICEโคCALL GIRL
Bhimtal โคCALL GIRL 8617697112 โคCALL GIRLS IN Bhimtal ESCORT SERVICEโคCALL GIRLNitya salvi
ย 
๐Ÿ“ž Contact Number 8617697112 VIP Ganderbal Call Girls
๐Ÿ“ž Contact Number 8617697112 VIP Ganderbal Call Girls๐Ÿ“ž Contact Number 8617697112 VIP Ganderbal Call Girls
๐Ÿ“ž Contact Number 8617697112 VIP Ganderbal Call GirlsNitya salvi
ย 

Recently uploaded (20)

Beautiful ๐Ÿ˜‹ Call girls in Lahore 03210033448
Beautiful ๐Ÿ˜‹ Call girls in Lahore 03210033448Beautiful ๐Ÿ˜‹ Call girls in Lahore 03210033448
Beautiful ๐Ÿ˜‹ Call girls in Lahore 03210033448
ย 
Goa Call Girls 9316020077 Call Girls In Goa By Russian Call Girl in goa
Goa Call Girls 9316020077 Call Girls  In Goa By Russian Call Girl in goaGoa Call Girls 9316020077 Call Girls  In Goa By Russian Call Girl in goa
Goa Call Girls 9316020077 Call Girls In Goa By Russian Call Girl in goa
ย 
๐“€คCall On 6297143586 ๐“€ค Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...
๐“€คCall On 6297143586 ๐“€ค Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...๐“€คCall On 6297143586 ๐“€ค Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...
๐“€คCall On 6297143586 ๐“€ค Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...
ย 
Independent Hatiara Escorts โœ” 9332606886โœ” Full Night With Room Online Booking...
Independent Hatiara Escorts โœ” 9332606886โœ” Full Night With Room Online Booking...Independent Hatiara Escorts โœ” 9332606886โœ” Full Night With Room Online Booking...
Independent Hatiara Escorts โœ” 9332606886โœ” Full Night With Room Online Booking...
ย 
5* Hotels Call Girls In Goa {{07028418221}} Call Girls In North Goa Escort Se...
5* Hotels Call Girls In Goa {{07028418221}} Call Girls In North Goa Escort Se...5* Hotels Call Girls In Goa {{07028418221}} Call Girls In North Goa Escort Se...
5* Hotels Call Girls In Goa {{07028418221}} Call Girls In North Goa Escort Se...
ย 
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
ย 
๐“€คCall On 6297143586 ๐“€ค Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...
๐“€คCall On 6297143586 ๐“€ค Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...๐“€คCall On 6297143586 ๐“€ค Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...
๐“€คCall On 6297143586 ๐“€ค Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...
ย 
Call Girls Agency In Goa ๐Ÿ’š 9316020077 ๐Ÿ’š Call Girl Goa By Russian Call Girl ...
Call Girls  Agency In Goa  ๐Ÿ’š 9316020077 ๐Ÿ’š Call Girl Goa By Russian Call Girl ...Call Girls  Agency In Goa  ๐Ÿ’š 9316020077 ๐Ÿ’š Call Girl Goa By Russian Call Girl ...
Call Girls Agency In Goa ๐Ÿ’š 9316020077 ๐Ÿ’š Call Girl Goa By Russian Call Girl ...
ย 
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
ย 
Almora call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment Booking
Almora call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment BookingAlmora call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment Booking
Almora call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment Booking
ย 
Kanpur call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment BookingKanpur call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls ๐Ÿ“ž 8617697112 At Low Cost Cash Payment Booking
ย 
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
ย 
Independent Joka Escorts โœ” 8250192130 โœ” Full Night With Room Online Booking 2...
Independent Joka Escorts โœ” 8250192130 โœ” Full Night With Room Online Booking 2...Independent Joka Escorts โœ” 8250192130 โœ” Full Night With Room Online Booking 2...
Independent Joka Escorts โœ” 8250192130 โœ” Full Night With Room Online Booking 2...
ย 
โคPersonal Whatsapp Number Keylong Call Girls 8617697112 ๐Ÿ’ฆโœ….
โคPersonal Whatsapp Number Keylong Call Girls 8617697112 ๐Ÿ’ฆโœ….โคPersonal Whatsapp Number Keylong Call Girls 8617697112 ๐Ÿ’ฆโœ….
โคPersonal Whatsapp Number Keylong Call Girls 8617697112 ๐Ÿ’ฆโœ….
ย 
Dakshineswar Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Se...
Dakshineswar Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Se...Dakshineswar Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Se...
Dakshineswar Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Se...
ย 
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
ย 
Sonagachi ( Call Girls ) Kolkata โœ” 6297143586 โœ” Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata โœ” 6297143586 โœ” Hot Model With Sexy Bhabi Rea...Sonagachi ( Call Girls ) Kolkata โœ” 6297143586 โœ” Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata โœ” 6297143586 โœ” Hot Model With Sexy Bhabi Rea...
ย 
Nayabad Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Sex At ...Nayabad Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls โœ” 8005736733 โœ” Hot Model With Sexy Bhabi Ready For Sex At ...
ย 
Bhimtal โคCALL GIRL 8617697112 โคCALL GIRLS IN Bhimtal ESCORT SERVICEโคCALL GIRL
Bhimtal โคCALL GIRL 8617697112 โคCALL GIRLS IN Bhimtal ESCORT SERVICEโคCALL GIRLBhimtal โคCALL GIRL 8617697112 โคCALL GIRLS IN Bhimtal ESCORT SERVICEโคCALL GIRL
Bhimtal โคCALL GIRL 8617697112 โคCALL GIRLS IN Bhimtal ESCORT SERVICEโคCALL GIRL
ย 
๐Ÿ“ž Contact Number 8617697112 VIP Ganderbal Call Girls
๐Ÿ“ž Contact Number 8617697112 VIP Ganderbal Call Girls๐Ÿ“ž Contact Number 8617697112 VIP Ganderbal Call Girls
๐Ÿ“ž Contact Number 8617697112 VIP Ganderbal Call Girls
ย 

Cakefest 2010: API Development

  • 1. API Development Becoming the Platform (CakePHP for Back-End Development or Cake for Web Services) By Andrew Curioso CakeFest 2010
  • 2. Introduction Yesterday: Designing CakePHP plug-ins for consuming APIs Today: Create your own API Basic setup Extras
  • 3. Become a platform Be โ€œaโ€ platform A blog is a platform
  • 4. Become a platform Internal only (closed) Multi-platform (consumers) Scalable External (open) Everything + Growth Mash-ups! Innovation Evangelists โ€œThe Platform Playโ€
  • 5. Whoโ€™s already a platform Google Facebook Digg Twitter Yahoo BOSS / Flickr / Delicious / etc. Salesforce Ebay Amazon Gowalla FourSquare Bit.ly Paypal Authorize.net Etcโ€ฆ
  • 6. Types of APIs Patterns Representation State Transfer (REST) Remote Procedure Calls (RPC) Protocols / Formats XML JSON YAML AMF Etc...
  • 7. RESTful Representational State Transfer Resource based (nouns) 5 verbs GET PUT POST DELETE HEAD Easy in CakePHP
  • 8. Todayโ€™s App URL shortening website User authentication (simple) Create, read, update, and delete (CRUD)
  • 9. Models id user_id url created modified users urls
  • 10. Making it RESTful APP/config/routes.php Router::mapResource(โ€˜usersโ€™) Source: http://book.cakephp.org/view/1239/The-Simple-Setup
  • 11.
  • 12. Mapping Extensions Router::parseExtensions() RequestHandler component Switches layouts / views Includes helpers Parses incoming XML on POST Router::connect( "/:controller/:idโ€, array ("action" => "edit", "[method]" => "PUT"), array("id" => "[0-9]+โ€) ); Source: http://book.cakephp.org/view/1240/Custom-REST-Routing
  • 13. Json View Simple Fast Wide-spread <?php echo json_encode( $url ); ?> APP/views/urls/json/view.ctp
  • 14. JsonP P ๏ƒจw/ padding Uses callback Cross domain <?php if ( $callbackFunc !== false ) echo $callbackFunc.'('; echo $content_for_layout; if ( $callbackFunc ) echo $callbackFunc.')'; ?> function beforeFilter() { if ( array_key_exists('callbackโ€™, $this->params[โ€˜urlโ€™]) ) $this->set(โ€˜callbackFuncโ€™, $this->params[โ€˜urlโ€™][โ€˜callbackโ€™]); else $this->set(โ€˜callbackFuncโ€™, false); } APP/views/layouts/json/default.ctp APP/app_controller.php
  • 15. XML View Strongly Typed Human readable Lots of existing tools <? echo โ€˜<url>โ€™; echo $xml->serialize( $url ); echo โ€˜<url>โ€™; ?> APP/views/urls/xml/view.ctp
  • 16. Other Views Human Readable XML Json / JsonP HTML YAML CSV Serialized PHP Etcโ€ฆ Binary AMF Microsoft Excel PDF JPEG / PNG Etcโ€ฆ
  • 17. Testing It Out Using cURL Create curl โ€“d โ€œurl=www.example.comโ€ http://tinyr.me/urls.json Read curl http://tinyr.me/urls/123.json Update curl โ€“d โ€œurl=www.example.com/fooโ€ http://tinyr.me/urls/123.json Delete curl โ€“X DELETE http://tinyr.me/urls/123.json
  • 18. Done? We have MVC files RESTful Views XML Json / JsonP Weโ€™re missing Error handling Pagination Authentication Authorization Documentation
  • 19. Status Codes Success 200 OK * 201 Created * 303 See Other * Error 401 Unauthorized * 402 Payment Required 403 Forbidden * 404 Not Found * Error (continued) 405 Method Not Allowed * 409 Conflict 410 Gone 500 Internal Server Error 501 Not Implemented 503 Service Unavailable
  • 20. Add Method If not a POST request 405 Method Not Allowed Already existed 303 See Other Save success 201 Created Failure 200 OK with explanation
  • 21. Edit Method If not a POST or PUT request 405 Method Not Allowed Invalid ID 404 File Not Found Success 200 OK Failure 200 OK with explanation
  • 22. Delete Method If not a POST or DELETE request 405 Method Not Allowed Invalid ID 404 File Not Found Success 200 OK Failure 200 OK with explanation
  • 23. Global User is not allowed to access resource 403 Forbidden User is not logged in 401 Unauthorized
  • 24. Throwing Errors Same format Descriptive Human Computer Comprehensive
  • 25. Implementation function your_action() { โ€ฆ $this->_userError(404); โ€ฆ } APP/controllers/your_controller.php function _userError( $code, $options=array() ) { $codes = array( 402 => 'Payment Required', โ€ฆ ); $this->header("HTTP/1.1 {$type} {$codes[$type]}"); $this->cakeError('error'.$type, array( array( 'options' => $options ) ) ); } APP/app_controller.php
  • 26. Implementation {"Error": { "code" : 404, "description" : "File Not Found" }} APP/views/errors/error404.ctp
  • 27. HTTP Headers Return meta-information Rate limiting Pagination Etc.
  • 28. Pagination Uses HTTP headers App defined start with โ€œX-โ€ function paginate($object=NULL, $scope=array(), $whitelist=array() ) { $data = parent::paginate($object,$scope,$whitelist); // โ€ฆ messy code to get the object โ€ฆ $this->header('X-Current-Page: '.((int)$this->params['paging'][$object->alias]['page'])); $this->header('X-Page-Limit: '.((int)$this->params['paging'][$object->alias]['options']['limit'])); $this->header('X-Page-Total: '.((int)$this->params['paging'][$object->alias]['count'])); return $data; } APP/app_controller.php
  • 29. Multi-Platform Dev Use a UI that makes sense Bring something to the table
  • 30. Platform Support Web Browsers Do not support: DELETE PUT Fortunately Cakeโ€ฆ Letโ€™s you do this: _method=DELETE
  • 31. Platform Support DELETE /urls/123.json HTTP1.1 Host: www.example.com POST /urls/123.json HTTP1.1 Host: www.example.com _method=DELETE
  • 33. Authorization There is no magic One or more: user_id Administrator Moderator
  • 34. Documentation Vocabularies / Schemas DTD or schema files Examples Code I/O Community Feedback
  • 35. What about SOAP and AMF? CakePHP rocks with REST SOAP is heavy AMF is light but requires Flash But, if you still want to, you can
  • 36. Flow for SOAP and AMF
  • 37. Example Flow Router UrlsController AmfController User POST ::gateway() ::view() Return data Format envelope
  • 40. API Developers Checklist Documentation Example code Definition files (if applicable) Unit tests
  • 41. Finding the code MIT License http://tinyr.me
  • 42. Happy Aniversary Happy anniversary, Laura. 1 year: Sept. 5, 2010
  • 43. Andrew Curioso Contact: www.AndrewCurioso.com/contact @AndrewCurioso on Twitter

Editor's Notes

  1. Who am I.Introduce myVBO.About this presentation.What Iโ€™ll talk about.
  2. Neil โ€“ plugins to consumeNot much code.Overview.All the slides will be online right after lunch.
  3. Raise your hand up if you use CakePHP to handle some kind of data.Now put your hand down if you donโ€™t have an API.If you have info why not be a platform?It doesnโ€™t matter if the platform is very simple. A blog is a platform. It has an API for posting new articles and it has an RSS feed for syndicating them.Now that I simplified it.Thatโ€™s my take.
  4. Even if you are developing a closed APIโ€ฆI hope everyone considers open APIs.All this roles up into one concept. โ€œThe platform play.โ€ So if you need something to go back to your boss or your investors withโ€ฆ thatโ€™s the thing. Youโ€™re making a platform play.
  5. If this was five years ago...But the strategy works pretty well. TwitterFacebookBit.lyAmazonandSalesforceNow it is almost a necessity to have an API of some sort.
  6. There are multiple patterns for APIs. There are a couple more lesser used ones but the two big ones are REST and RPC.Within those patterns you can use one or more formats to transfer your data.
  7. Rest stands for Representational State Transfer incase you missed it in Nealโ€™s presentation. As mentioned yesterday, the largest example of REST in the wild is HTTP.Luckily for us, CakePHP is usually layered on-top of HTTP so it inherits all the RESTful mechanisms.REST has a concept called resources (a specific user or comment are two examples).They are also called nouns which are acted on by verbs.There are five verbs in HTTP. We will focus on three.Finally, one last important thingโ€ฆ CakePHP makes REST easy.
  8. The app that I will be using as an example today is the simplest app that I could think of.It is a URL shortening services that allows you to authenticate and thus be able to delete and edit URLs that you yourself shortened, and also basic CRUD.
  9. There are two models. The user model, which is pretty standard for a CakePHP project, and the urls model which I have on the screen.A full URL shortened can, of course, get much more complicated than that. But for today Iโ€™m keeping it basic.
  10. Once youโ€™ve baked your model and what not you can open up your router and map the resource. This will register all the routes you need for REST in one call.You can still do it manually if you want but you donโ€™t have to.These are the six routes registered when you map a resource.
  11. One rule to live by is to never write or delete data on anything that is not a POST, PUT, or DELETE request.The main purpose of this rule is to protect against Cross Site Request Forgeries or CSRF attacks which are every difficult to defend against otherwise.Say that the add method accepted GET requests. Someone could then simply embed an image on a page with the add URL as a source and execute a add() as any user who visits the site.
  12. Before we begin developing views weโ€™ll haveto tell PHP to recognize file extensions and switch the views and layouts accordingly.We do this by turning on parseExtensions in the routes.php file and including the RequestHandler component in the app_controller.The RequestHandler component is what actually switches the views. It also includes helpers automatically in the view if a helper has the same name as the extension (like XML) and parses incoming POSTed XML and assigns it to the data property of the controller.
  13. We now need to create a couple views.The Json view is the first and the one that I like the most. Because it is simple and easy to understand.It is fast thanks to native PHP support, and also very wide-spread.What you see here is the entire view for the view action in the urls controller.Notice the path to the view. The RequestHandler will tell Cake to look in the json folder for the appropriate view.
  14. We can also easily support JsonP or Json with padding.JsonP specifies a Javascript callback function to execute with the results of a request.It allows for cross domain requests because you can trigger it via a simple script-include and function calls works across domains so the callback will work just fine.One important note is that it is only for GET requests. So, as I said earlier, it shouldnโ€™t be able to write or delete data.JsonP can be handle generically in the layout. Notice the layout path.A JsonP request always takes the callback via a query parameter. So your app controller can read in the callback then set it for use in the view. The layout then reads it sand wraps the output in it is necessary.
  15. Now for the XML view. And I can hear the boos now.XML does have some benefits. It is strongly typed, human readable, and has lots of existing tools available.Like Json, the view is pretty self-explanatory. Note the xml sub-directory in the view path.
  16. One of the best parts about using parseExtensions and RequestHandler is you can literally have as many views as you want into the data.I listed just some of them here.
  17. Erikโ€™s talk.
  18. If you did the ACL stuff Erik was talking aboutโ€ฆLittle difficult. Default behavior is redirectController, model, and object
  19. Maintenance mode