Your SlideShare is downloading. ×
0
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Building custom APIs
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Building custom APIs

1,178

Published on

Slides from the talk given by Charlie van de Kerkhof during the CakeFest #3 - July 2009 …

Slides from the talk given by Charlie van de Kerkhof during the CakeFest #3 - July 2009

Note: the original pdf and the code related to this talk can be found on cakephp.org

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,178
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
29
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Courier New Bold 18 pt Charlie-preso Building a custom API by Charlie van de Kerkhof (primeminister) CakeFest #3 July 2009
  • 2. Goals • RESTful with the correct HTTP code • API like twitter to open up to the public in the near future • Smooth integration with code for the website • Return values HTML, XML and JSON • Not necessarily the correct methods (POST,GET,DELETE,PUT)
  • 3. What is it? • Link sharing (like del.icio.us) with groups and users • Comments on links • Trusted group of friends • Links are not necessarily bookmarks!
  • 4. Setup • Database • Routes • Model • Controller • Views (HTML, XML & JSON) • Tests
  • 5. Database
  • 6. Models • Baked the associations • Basic validation in model • AppModel: Using containable • AppModel: Overwrite del() method for using ‘status’ field in tables.
  • 7. AppController • Setting up helpers and components • Mapping request methods to actions • Defining up HTTP response codes • Populate POST request to $this->data Because this APP is also meant to get data from HTML forms
  • 8. GET Request /links/view/primeminister.xml • Controller => links, action => view params[‘pass’][0] = ’primeminister’ • Check nickname variable • Find the links from this user • Set the results and options
  • 9. APP/controllers/links_controller.php
  • 10. Error occurs f.i. nickname is not same as loggedin user • Calls AppController::setError() • setError() checks which request is made (XML, JSON, HTML) • When HTML is requested it calls the Session::setFlash method • Other requests it sets the viewVars and renders the error template errcode & code: errcode: to define f.e. 1007 what is missing. For developers handy to program Code: HTTP response code
  • 11. APP/controllers/links_controller.php
  • 12. APP/app_controller.php
  • 13. continue... APP/app_controller.php
  • 14. continue... APP/app_controller.php
  • 15. Views • Created generic template files • XML: Xml::serialize with format=>tags • JSON with $javascript->object($record); • When necessary create template file in views/{controller} folder to override generic template • Put this check in AppController::beforeRender
  • 16. APP/views/generic/xml/view.ctp
  • 17. APP/views/generic/json/view.ctp
  • 18. APP/views/links/xml/view.ctp
  • 19. Links view (XML) /links/view/primeminister.xml?limit=2&page=3
  • 20. Error view (XML)
  • 21. Routes
  • 22. Controller tests • Test made on controller actions • Checks for view variables • errocode & code check • Don’t forget to check on errors!
  • 23. tests/cases/controllers/links_controllers.test.php
  • 24. Summarize
  • 25. • Loosely map request method (POST/ GET/...) to action • For using in website and as API (!) • Return response codes and Mento errors • Easier for developer to check what error • Rendering views based on generic template • Tests on controller and viewVars (code)
  • 26. Question (& Answers?)
  • 27. Thanks! Web: http://www.cake-toppings.com IRC: primeminister Twitter: http://twitter.com/charli3

×