hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php
DESCRIPTION
TRANSCRIPT
![Page 1: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/1.jpg)
BuildingBuildingRESTful Web Service RESTful Web Service With PHPWith PHPHuy Nguyen - Huy Nguyen - [email protected]
![Page 2: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/2.jpg)
REST and RESTful web service Building a RESTful framework with PHP
![Page 3: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/3.jpg)
REpresentational State Transfer
An architecture not a protocol or a standard Resource Oriented Approach World Wide Web is the key example
![Page 4: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/4.jpg)
What is a RESTful web service?
A web site for Machines!!!A web site for Machines!!!
![Page 5: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/5.jpg)
It's all about HTTP, dude!
GET POST PUT DELETE HEAD OPTIONS
URIs
MIME types supported
Resources
![Page 6: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/6.jpg)
REST vs RPC
RESOURCES vs FUNCTIONS
ROA vs SOA
![Page 7: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/7.jpg)
Flickr has a RESTful web service
But it's crap!!!!!!!
![Page 8: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/8.jpg)
This is RESTful: http://feeds.feedburner.com/Geshansblog
and this is not: http://api.flickr.com/services/rest/?method=flickr.test.echo&name=value
![Page 9: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/9.jpg)
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 ...
![Page 10: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/10.jpg)
Now let's talk about PHP
... and how it supports REST
![Page 11: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/11.jpg)
$_SERVER
Accept => $_SERVER['HTTP_ACCEPT']
Request Method => $_SERVER['REQUEST_METHOD']
![Page 12: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/12.jpg)
$_POST and $_GET
Everyone knows them!
![Page 13: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/13.jpg)
RAW POST/PUT REQUEST DATA?
<?php
// get RAW HTTP POST$rawData = file_get_contents('php://input');
// but this won't work with enctype="multipart/form-data" :(
![Page 14: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/14.jpg)
Why is symfony not RESTful?
because RESTful web service is about resources, not functions/actions
![Page 15: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/15.jpg)
My RESTful Framework
Creating Resources Creating URIs Handling HTTP methods MIME-type support
![Page 16: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/16.jpg)
Resources As Controllers
A resources is a class that handles HTTP methods
![Page 17: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/17.jpg)
/** * 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); }
![Page 18: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/18.jpg)
/** * HTTP DELETE handler */ public function __handleDelete() { // Not implemented $this->_response->setResponseCode(501); } /** * HTTP HEAD handler */ public function __handleHead() { // Not implemented $this->_response->setResponseCode(501); }
![Page 19: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/19.jpg)
Creating The URIs
/blog/([a-zA-Z0-9]+)/? => blogResource
![Page 20: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/20.jpg)
Composite Resources
Konstrukt Framework(konstrukt.dk)
![Page 21: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/21.jpg)
![Page 22: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/22.jpg)
MIME Types & Multiple Views
$_SERVER['HTTP_ACCEPT']
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
![Page 23: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/23.jpg)
My framework is called My framework is called KaoKao
![Page 24: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/24.jpg)
Thank you! I love PHP!
![Page 25: Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-with-php](https://reader033.vdocuments.net/reader033/viewer/2022061206/54770becb4af9fe7248b46a3/html5/thumbnails/25.jpg)
Any Question?