Building RESTful Web Service  With PHP Huy Nguyen -  [email_address]
REST and RESTful web service Building a RESTful framework with PHP
RE presentational  S tate  T ransfer An architecture not a protocol or a standard Resource Oriented Approach World Wide Web is the key example
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=flickr.test.echo&name=value
RESTful Web Protocols Syndication protocols (RSS, Atom Feed)‏ Atom Publishing Protocol RDF and OWL OpenID Single Sign-on Standard Google's OpenSocial Protocol Amazon's S3 Protocol ...
Now let's talk about PHP ... and how it supports REST
$_SERVER Accept   =>   $_SERVER [ 'HTTP_ACCEPT' ] Request Method   =>   $_SERVER [ 'REQUEST_METHOD' ]
$_POST and $_GET Everyone knows them!
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; :(
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 Controllers A resources is a class that handles HTTP methods
/** * 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); }
/** * HTTP DELETE handler */ public function  __handleDelete ()‏ { // Not implemented $this->_response->setResponseCode(501); } /** * HTTP HEAD handler */ public function  __handleHead ()‏ { // Not implemented $this->_response->setResponseCode(501); }
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?

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

  • 1.
    Building RESTful WebService With PHP Huy Nguyen - [email_address]
  • 2.
    REST and RESTfulweb service Building a RESTful framework with PHP
  • 3.
    RE presentational S tate T ransfer An architecture not a protocol or a standard Resource Oriented Approach World Wide Web is the key example
  • 4.
    What is aRESTful web service? A web site for Machines!!!
  • 5.
    It's all aboutHTTP, dude! GET POST PUT DELETE HEAD OPTIONS URIs MIME types supported Resources
  • 6.
    REST vs RPC RESOURCES vs FUNCTIONS ROA vs SOA
  • 7.
    Flickr has aRESTful web service But it's crap!!!!!!!
  • 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.
    RESTful Web ProtocolsSyndication protocols (RSS, Atom Feed)‏ Atom Publishing Protocol RDF and OWL OpenID Single Sign-on Standard Google's OpenSocial Protocol Amazon's S3 Protocol ...
  • 10.
    Now let's talkabout PHP ... and how it supports REST
  • 11.
    $_SERVER Accept => $_SERVER [ 'HTTP_ACCEPT' ] Request Method => $_SERVER [ 'REQUEST_METHOD' ]
  • 12.
    $_POST and $_GETEveryone knows them!
  • 13.
    RAW POST/PUT REQUESTDATA? <?php // get RAW HTTP POST $rawData = file_get_contents( 'php://input' ); // but this won't work with enctype=&quot;multipart/form-data&quot; :(
  • 14.
    Why is symfonynot RESTful? because RESTful web service is about resources, not functions/actions
  • 15.
    My RESTful FrameworkCreating Resources Creating URIs Handling HTTP methods MIME-type support
  • 16.
    Resources As ControllersA resources is a class that handles HTTP methods
  • 17.
    /** * HTTPGET 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.
    /** * HTTPDELETE handler */ public function __handleDelete ()‏ { // Not implemented $this->_response->setResponseCode(501); } /** * HTTP HEAD handler */ public function __handleHead ()‏ { // Not implemented $this->_response->setResponseCode(501); }
  • 19.
    Creating The URIs/blog/([a-zA-Z0-9]+)/? => blogResource
  • 20.
    Composite Resources KonstruktFramework (konstrukt.dk)‏
  • 21.
  • 22.
    MIME Types &Multiple Views $_SERVER [ 'HTTP_ACCEPT' ] text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  • 23.
    My framework iscalled Kao
  • 24.
    Thank you! I love PHP!
  • 25.