github github
  • Home
  • Pricing and Signup
  • Training
  • Gist
  • Blog
  • Login

diogok / restserver

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 6
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Switch Branches (1)
    • master ✓
  • Switch Tags (0)
  • Branch List
Sending Request…

RESTful resource/url mapping and MVC, featuring Request an Response objects. — Read more

  Cancel

http://www.phpclasses.org/browse/package/5080.html

  Cancel
  • HTTP
  • Git Read-Only

This URL has Read+Write access

Fixed redundant methods RestRequest::getInput and getBody and RestResponse::addResponse appendResponse, now they chain call the newer method. Did not removed duplicated due to backward compatibility and stuff like that. This is my longest commit message so far... 
diogok (author)
Thu Aug 12 17:07:00 -0700 2010
commit  b1e641c05d5d507d5810
tree    4326a6d862cc927adfc9
parent  330617e443421d5647aa
restserver /
name age
history
message
file COPYING.txt Tue Feb 17 05:25:01 -0800 2009 Adding base files [Diogo SOuza da Silva]
file GenericView.class.php Tue Dec 01 18:03:27 -0800 2009 Bugs fixes and Authenticator done for Basic and... [diogok]
file RestAction.class.php Tue Dec 01 18:03:27 -0800 2009 Bugs fixes and Authenticator done for Basic and... [diogok]
file RestAuthenticator.class.php Thu May 27 05:49:34 -0700 2010 Fixed parameter &-append bug, thx to Ian Gibbon... [diogok]
file RestClient.class.php Thu May 27 05:49:34 -0700 2010 Fixed parameter &-append bug, thx to Ian Gibbon... [diogok]
file RestController.class.php Tue Dec 01 18:03:27 -0800 2009 Bugs fixes and Authenticator done for Basic and... [diogok]
file RestRequest.class.php Thu Aug 12 17:07:00 -0700 2010 Fixed redundant methods RestRequest::getInput a... [diogok]
file RestResponse.class.php Thu Aug 12 17:07:00 -0700 2010 Fixed redundant methods RestRequest::getInput a... [diogok]
file RestServer.class.php Thu May 27 05:49:34 -0700 2010 Fixed parameter &-append bug, thx to Ian Gibbon... [diogok]
file RestView.class.php Tue Dec 01 18:03:27 -0800 2009 Bugs fixes and Authenticator done for Basic and... [diogok]
directory docs/ Thu May 27 05:49:34 -0700 2010 Fixed parameter &-append bug, thx to Ian Gibbon... [diogok]
file readme Tue Dec 01 18:09:29 -0800 2009 fixed readme info [diogok]
directory tests/ Thu May 27 05:49:34 -0700 2010 Fixed parameter &-append bug, thx to Ian Gibbon... [diogok]
readme
This package is intended for RESTful webservices or websites. 

Downloading the package just browser to docs directory to view api documentation, and to tests to run unit testing.

The purpose of this package is to Map URLs to Controller classes. The main class is the RestServer, wich is responsible for holding the Request, the Response, the Url map and to make decisions about what to load. 

You can map a URL by calling the method addMap() on a RestServer instance, as above:

$rest = new RestServer ;
$rest->addMap("GET","/user","UserController");

Instead of processing the requested URL, you may provide one by passing it to
the RestServer:

$rest = new RestServer($_GET["url"]);

The addMap() method takes three arguments, as follow:
1- The Request Method, ie:
1.1- GET, POST, PUT, DELETE, OPTION and others.
2- The URL pattern is a pearl compatible regular expression, but without delimiters.  Here are some examples:
2.1- "/","/user","/device/[a-z0-9]+","/post/[0-9]+/comments","/article/[0-9]*/photo/[0-9]*".
3- A controller/view class, that must implement RestController or RestView.  There are no naming conventions imposed by RestServer.
3.1- Can also specify a class method such as "Profile::full".  It will not be called staticly.

The Controller(preferred) or View to receive the request must implement RestController or RestView. The RestController should implement the execute() method receiving a RestServer as a parameter, as follow:

class Anything implements RestController {
    function execute(RestServer $rest) {
        // Logic here
        return $rest ;
    }
}

And the RestView implementation must use show() method also receiving a RestServer, as follow:

class Anyview implements RestView {
    function show(RestServer $rest) {
        //Logic here
        return $rest;
    }
}

Both need to have a parameter-free public constructor(or no constructor at all). Alternative methods must also receive the RestServer as a parameter. Ideally it should always return something, but that's not mandatory. One can return the RestServer, ending the session, or a RestAction(which is any RestController or RestView) to be taken next. Example:

class Anything implements RestController {
    function execute(RestServer $rest) {
        return new Anyview ;
    }
}

class Anyview implements RestView {
    function show(RestServer $rest) {
        return $rest;
    }
}

It also adds a convinience GenericView class, for basic templating on php scripts, as follow:

class Homepage implements RestController {
    function execute(RestServer $rest) {
        // Logic in here
        return new GenericView("path_to_php_script");
    }
}

For recovering information about the request taken, the RestServer provides the RestRequest object. You can get it by calling the getRequest() method on the RestServer.

To build up a response, the RestServer provide the Response Object.  Access it by calling the method getResponse() on the RestServer.

There is a new useful utility called RestClient, which can be used to call other webservices or to test your own. Refer to exemple3 and for the tests to see how it works

RestServer is compatible with quercus, and thus with Google App Engine.

Downloading the package just browser to docs directory to view api documentation, and to tests to run unit testing.

This was developed by Diogo Souza da Silva <manifesto@manifesto.blog.br>.
Dedicated Server Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
  • Blog
  • Support
  • Training
  • Job Board
  • Shop
  • Contact
  • API
  • Status
  • © 2010 GitHub Inc. All rights reserved.
  • Terms of Service
  • Privacy
  • Security
  • English
  • Deutsch
  • Français
  • 日本語
  • Português (BR)
  • 中文
  • See all available languages

Your current locale selection: English. Choose another?

  • English
  • Afrikaans
  • Català
  • Čeština
  • Deutsch
  • Español
  • Français
  • Hrvatski
  • Indonesia
  • Italiano
  • 日本語
  • Nederlands
  • Norsk
  • Polski
  • Português (BR)
  • Српски
  • Svenska
  • 中文