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>.
