BuildingRESTful Web ServiceWith PHPHuy Nguyen - huy@byhuy.com
    REST and RESTful web service    Building a RESTful framework with PHP
REpresentational State Transfer    An architecture not a protocol or a standard    Resource Oriented Approach    World ...
What is a RESTful web service?   A web site for Machines!!!
MIME typesGET    POSTPUT DELETE HEAD   supported   OPTIONSResources                   URIs     Its all about HTTP, dude!
REST vs RPC     ROA vs SOARESOURCES vs FUNCTIONS
Flickr has a RESTful web service        But its crap!!!!!!!
This is RESTful:http://feeds.feedburner.com/Geshansblogand this is not:http://api.flickr.com/services/rest/?method=flickr....
RESTful Web Protocols    Syndication protocols (RSS, Atom Feed)    Atom Publishing Protocol    RDF and OWL    OpenID S...
Now lets talk about PHP... and how it supports REST
$_SERVER Accept => $_SERVER[HTTP_ACCEPT]Request Method => $_SERVER[REQUEST_METHOD]
$_POST and $_GETEveryone knows them!
RAW POST/PUT REQUEST               DATA?<?php// get RAW HTTP POST$rawData = file_get_contents(php://input);// but this won...
Why is symfony not RESTful?because RESTful web service is about   resources, not functions/actions
My RESTful Framework    Creating Resources    Creating URIs    Handling HTTP methods    MIME-type support
Resources As ControllersA resources is a class that handles HTTP methods
/**   * HTTP GET handler   */  public function __handleGet()  {      // Not implemented      $this->_response->setResponse...
/**       * HTTP DELETE handler       */      public function __handleDelete()      {          // Not implemented         ...
Creating The URIs/blog/([a-zA-Z0-9]+)/?   =>   blogResource
Composite Resources  Konstrukt Framework     (konstrukt.dk)
MIME Types & Multiple Views         $_SERVER[HTTP_ACCEPT]text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
My framework is called Kao
Thank you! I love PHP!
Any Question?
nguyenhainhathuy-building-restful-web-service
Upcoming SlideShare
Loading in …5
×

nguyenhainhathuy-building-restful-web-service

1,063 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,063
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

nguyenhainhathuy-building-restful-web-service

  1. 1. BuildingRESTful Web ServiceWith PHPHuy Nguyen - huy@byhuy.com
  2. 2.  REST and RESTful web service Building a RESTful framework with PHP
  3. 3. REpresentational State Transfer An architecture not a protocol or a standard Resource Oriented Approach World Wide Web is the key example
  4. 4. What is a RESTful web service? A web site for Machines!!!
  5. 5. MIME typesGET POSTPUT DELETE HEAD supported OPTIONSResources URIs Its all about HTTP, dude!
  6. 6. REST vs RPC ROA vs SOARESOURCES vs FUNCTIONS
  7. 7. Flickr has a RESTful web service But its crap!!!!!!!
  8. 8. This is RESTful:http://feeds.feedburner.com/Geshansblogand this is not:http://api.flickr.com/services/rest/?method=flickr.test.echo&name=value
  9. 9. RESTful Web Protocols Syndication protocols (RSS, Atom Feed) Atom Publishing Protocol RDF and OWL OpenID Single Sign-on Standard Googles OpenSocial Protocol Amazons S3 Protocol ...
  10. 10. Now lets talk about PHP... and how it supports REST
  11. 11. $_SERVER Accept => $_SERVER[HTTP_ACCEPT]Request Method => $_SERVER[REQUEST_METHOD]
  12. 12. $_POST and $_GETEveryone knows them!
  13. 13. RAW POST/PUT REQUEST DATA?<?php// get RAW HTTP POST$rawData = file_get_contents(php://input);// but this wont work with enctype="multipart/form-data" :(
  14. 14. Why is symfony not RESTful?because RESTful web service is about resources, not functions/actions
  15. 15. My RESTful Framework Creating Resources Creating URIs Handling HTTP methods MIME-type support
  16. 16. Resources As ControllersA resources is a class that handles HTTP methods
  17. 17. /** * HTTP GET handler */ public function __handleGet() { // Not implemented $this->_response->setResponseCode(501); } /** * HTTP POST handler */ public function __handlePost() { // Not implemented $this->_response->setResponseCode(501); } /** * HTTP PUT handler */ public function __handlePut() { // Not implemented $this->_response->setResponseCode(501); }
  18. 18. /** * HTTP DELETE handler */ public function __handleDelete() { // Not implemented $this->_response->setResponseCode(501); } /** * HTTP HEAD handler */ public function __handleHead() { // Not implemented $this->_response->setResponseCode(501); }
  19. 19. Creating The URIs/blog/([a-zA-Z0-9]+)/? => blogResource
  20. 20. Composite Resources Konstrukt Framework (konstrukt.dk)
  21. 21. MIME Types & Multiple Views $_SERVER[HTTP_ACCEPT]text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  22. 22. My framework is called Kao
  23. 23. Thank you! I love PHP!
  24. 24. Any Question?

×