Re: REST - PHP Extension

From: Date: Mon, 03 Jan 2011 11:52:04 +0000
Subject: Re: REST - PHP Extension
References: 1 2  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-7906@lists.php.net to get a copy of this message
Hi Pierre, Thank you for quick response! As I noted in my initial email the extension is in it's early stage and such things like you mentioned about config.m4 are missing. Regarding HTTP/s extension, it is really comprehensive and does a lot of things perfectly, but: - In my knowledge it lacks routing completely (I provided examples of this in my previous email) - In client part there are a lot of small details that really simplifies building of clients for RESTful services, and for more clarity I can/will write more detailed documentations. Before I started working on this extension I quite carefully reviewed existing extensions(mainly HTTP and oAuth) and tried to avoid duplications as much as it is possible. Best regards, Ioseb On Mon, Jan 3, 2011 at 3:46 PM, Pierre Joye <pierre.php@gmail.com> wrote: > hi Ioseb, > > A couple of short comments after a quick review: > > - which license will you use? > - config.m4 misses curl detection, a --with-libcurl or change to > --with-rest=<path to curl prefix> should be added > > > However I'm not sure it is worth the effort to do such things in an > extension. With the existing HTTP/s layers in php or using the > outstanding pecl's http extension, most of what is done in this > extension is already implemented and tested (as in kown special cases > have been catched). > > Cheers, > > On Mon, Jan 3, 2011 at 12:08 PM, Ioseb Dzmanashvili > <ioseb.dzmanashvili@gmail.com> wrote: > > Dear All, > > > > I'm Ioseb Dzmanashvili, software engineer from Republic of Georgia. > Recently > > I begun working on quite huge corporate project, one of the main purposes > of > > this project is to build RESTful API layer in front of each system for > > simplifying and improving interoperability between various systems. As > was > > decided I begun implementing REST client and server as a separate PHP > > extension. I got permission from my boss to open source this project and > as > > was recommended on pecl.php.net I want to introduce this extension. > > > > Extension consist of two parts: > > > >> Client - for easily and effectively building clients for any RESTful > > resource; and > >> Server - for building RESTful resources. > > > > API for both parts is pretty straightforward. Below are presented some > usage > > examples of RestServer, in case of interest I'll send examples of > RestClient > > as well. You can see the source of the current implementation at > > https://github.com/ioseb/rest , please note that it's > > in a very early > stage > > of development and is far from polished and finished product. > > > > Thank you in advance! > > > > *RestServer example:* > > > > $server = new RestServer( > > '/test/filter/index.php' //service endpoint > > ); > > > > $server->addRoute(array( > > /** > > * path template, will be compiled to: > > * > > > > ~^/news/?(?P<hola>(?:/[-\w]+)+)/(?P<test>(?:/?[^/]*))/(?P<path>pppp)/1/(?P<token>tttt)/?(?P<date>(?:/\d+)+)$~ > > */ > > '#path' => '/news/{hola}/{test}/{path}/1/{token}/{date}', > > '#tokens' => array( > > 'token' => 'tttt', //match tttt > > 'path' => 'pppp', //match pppp > > 'hola' => REST_ROUTE_PATTERN_ALPHA_TOKENS, //match /abc/efd/123 type > > alphanumeric sub path > > 'date' => REST_ROUTE_PATTERN_DIGIT_TOKENS, //match /12/34/56/78 type > > numeric sub path > > ), > > '#get' => 'getResponse', //callback for HTTP > > GET > > method > > ))->addRoute(array( > > /** > > * path template, will be compiled to: > > * ~^/hello/?(?P<hola>(?:/.+)+)$~ > > */ > > '#path' => '/news/{hola}', > > '#tokens' => array( > > 'hola' => REST_ROUTE_PATTERN_TOKENS, //match /abc/efd/123 type > > sub path, any characters allowed > > ), > > '#get' => 'getResponse', //callback for HTTP > > GET > > method > > )); > > > > try { > > $result = $server->handleQueryParam('q'); //try to match path provided > as > > a query parameter e.g. ?q=/path/to/some/resource > > //$result = $server->handleRequestUri(); //try to match path > provided > > as a request URI e.g. > > http://domain.com/service-endpoint/path/to/some/resource > > //$result = $server->handle('/path/to/some/resource'); //try to > match > > path provided as a regular method parameter > > } catch (Exception $ex) { > > printf('<pre>%s</pre>', print_r($ex, TRUE)); > > } > > > > function getResponse($args) { > > print_r($args); > > } > > > > *Printed result by "getResponse($args)" callback for: > > > > http://localhost/test/filter/index.php?q=/news/a1/b2/g3/d4/e5* > > > > Array > > ( > > [hola] => Array > > ( > > [0] => a1 > > [1] => b2 > > [2] => g3 > > [3] => d4 > > [4] => e5 > > ) > > > > ) > > > > *Printed result by "getResponse($args)" callback for** for: > > > > http://localhost/test/filter/index.php?q=/news/a1/b2/g3/d4/e5/kjjhll/pppp/1/tttt/10/20/30* > > > > Array > > ( > > [hola] => Array > > ( > > [0] => a1 > > [1] => b2 > > [2] => g3 > > [3] => d4 > > [4] => e5 > > ) > > > > [test] => kjjhll > > [path] => pppp > > [token] => tttt > > [date] => Array > > ( > > [0] => 10 > > [1] => 20 > > [2] => 30 > > ) > > > > ) > > > > *Dump of $server object:* > > > > RestServer Object > > ( > > [endpoint] => /test/filter/index.php > > [routes] => Array > > ( > > [0] => Array > > ( > > [#path] => /news/{hola}/{test}/{path}/1/{token}/{date} > > [#tokens] => Array > > ( > > [token] => tttt > > [path] => pppp > > [hola] => (?:/[-\w]+)+ > > [date] => (?:/\d+)+ > > ) > > > > [#get] => getResponse > > [#expr] => > > > > ~^/news/?(?P<hola>(?:/[-\w]+)+)/(?P<test>(?:/?[^/]*))/(?P<path>pppp)/1/(?P<token>tttt)/?(?P<date>(?:/\d+)+)$~ > > ) > > > > [1] => Array > > ( > > [#path] => /news/{hola} > > [#tokens] => Array > > ( > > [hola] => (?:/.+)+ > > ) > > > > [#get] => getResponse > > [#expr] => ~^/news/?(?P<hola>(?:/.+)+)$~ > > ) > > > > ) > > > > ) > > > > > > Best regards, > > Ioseb > > -- > > Ioseb Dzmanashvili > > Senior Software Architect > > Picktek LLC > > 41 Vazha-Pshavela ave. > > Tbilisi, 0177, Georgia > > T (+995 32) 39.58.56, F (+1 202) 315.3934 > > picktek.com > > github.com/ioseb > > twitter.com/iosebi > > > > > > -- > Pierre > > @pierrejoye | http://blog.thepimp.net | > http://www.libgd.org > -- Ioseb Dzmanashvili Senior Software Architect Picktek LLC 41 Vazha-Pshavela ave. Tbilisi, 0177, Georgia T (+995 32) 39.58.56, F (+1 202) 315.3934 picktek.com github.com/ioseb twitter.com/iosebi

« previous php.pecl.dev (#7906) next »