Building RESTful Web Service  With PHP Huy Nguyen -  [email_address]
<ul><li>REST and RESTful web service </li></ul><ul><li>Building a RESTful framework with PHP </li></ul>
RE presentational  S tate  T ransfer <ul><li>An architecture not a protocol or a standard </li></ul><ul><li>Resource Orien...
What is a RESTful web service? A web site for Machines!!!
It's all about HTTP, dude! GET  POST  PUT  DELETE  HEAD  OPTIONS  URIs MIME types supported Resources
REST  vs   RPC RESOURCES  vs   FUNCTIONS ROA  vs   SOA
Flickr has a RESTful web service But it's crap!!!!!!!
This is RESTful:  http://feeds.feedburner.com/Geshansblog and this is not:  http://api.flickr.com/services/rest/?method=fl...
RESTful Web Protocols <ul><li>Syndication protocols (RSS, Atom Feed)‏ </li></ul><ul><li>Atom Publishing Protocol </li></ul...
Now let's talk about PHP ... and how it supports REST
$_SERVER <ul><ul><li>Accept   =>   $_SERVER [ 'HTTP_ACCEPT' ] </li></ul></ul>Request Method   =>   $_SERVER [ 'REQUEST_MET...
$_POST and $_GET <ul><ul><li>Everyone knows them! </li></ul></ul>
RAW POST/PUT REQUEST DATA? <?php // get RAW HTTP POST $rawData   = file_get_contents( 'php://input' ); // but this won't w...
Why is symfony not RESTful?  because RESTful web service is about resources, not functions/actions
My RESTful Framework <ul><li>Creating Resources </li></ul><ul><li>Creating URIs </li></ul><ul><li>Handling HTTP methods </...
Resources As Controllers A resources is a class that handles HTTP methods
/** * HTTP GET handler */ public function  __handleGet ()‏ { // Not implemented $this->_response->setResponseCode(501); } ...
/** * HTTP DELETE handler */ public function  __handleDelete ()‏ { // Not implemented $this->_response->setResponseCode(50...
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?
Upcoming SlideShare
Loading in...5
×

Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php

1,130

Published on

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

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

No notes for slide

Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php

  1. 1. Building RESTful Web Service With PHP Huy Nguyen - [email_address]
  2. 2. <ul><li>REST and RESTful web service </li></ul><ul><li>Building a RESTful framework with PHP </li></ul>
  3. 3. RE presentational S tate T ransfer <ul><li>An architecture not a protocol or a standard </li></ul><ul><li>Resource Oriented Approach </li></ul><ul><li>World Wide Web is the key example </li></ul>
  4. 4. What is a RESTful web service? A web site for Machines!!!
  5. 5. It's all about HTTP, dude! GET POST PUT DELETE HEAD OPTIONS URIs MIME types supported Resources
  6. 6. REST vs RPC RESOURCES vs FUNCTIONS ROA vs SOA
  7. 7. Flickr has a RESTful web service But it's crap!!!!!!!
  8. 8. This is RESTful: http://feeds.feedburner.com/Geshansblog and this is not: http://api.flickr.com/services/rest/?method=flickr.test.echo&name=value
  9. 9. RESTful Web Protocols <ul><li>Syndication protocols (RSS, Atom Feed)‏ </li></ul><ul><li>Atom Publishing Protocol </li></ul><ul><li>RDF and OWL </li></ul><ul><li>OpenID Single Sign-on Standard </li></ul><ul><li>Google's OpenSocial Protocol </li></ul><ul><li>Amazon's S3 Protocol </li></ul><ul><li>... </li></ul>
  10. 10. Now let's talk about PHP ... and how it supports REST
  11. 11. $_SERVER <ul><ul><li>Accept => $_SERVER [ 'HTTP_ACCEPT' ] </li></ul></ul>Request Method => $_SERVER [ 'REQUEST_METHOD' ]
  12. 12. $_POST and $_GET <ul><ul><li>Everyone knows them! </li></ul></ul>
  13. 13. RAW POST/PUT REQUEST DATA? <?php // get RAW HTTP POST $rawData = file_get_contents( 'php://input' ); // but this won't work with enctype=&quot;multipart/form-data&quot; :(
  14. 14. Why is symfony not RESTful? because RESTful web service is about resources, not functions/actions
  15. 15. My RESTful Framework <ul><li>Creating Resources </li></ul><ul><li>Creating URIs </li></ul><ul><li>Handling HTTP methods </li></ul><ul><li>MIME-type support </li></ul>
  16. 16. Resources As Controllers A 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. 22. MIME Types & Multiple Views $_SERVER [ 'HTTP_ACCEPT' ] text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  22. 23. My framework is called Kao
  23. 24. Thank you! I love PHP!
  24. 25. Any Question?
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×