<commit_before>##A "thin" REST-full server implementation in PHP 
RestLt is a flexible small library that will allow you to build RESTfull service.
Most of the sub-components are extensible or replaceable. This would let you modify the server's behavior.
Any feedback is appreciated!


[![Build Status](https://travis-ci.org/ivolator/restlt.png)](https://travis-ci.org/ivolator/restlt)
##Installing
###Using Composer
In require section of your composer.json file add the information for RestLt as follows:
```
{ 
        "require" :
        { 
                "restlt/restlt":"1.0.3b"
        }
}
```
Run `composer.phar --dev update`

###Clone with GIT
Use this URL to clone the repo
`https://github.com/ivolator/restlt.git`

##Basics 
###Server end point setup
```php
//Get instance of the server by passing the server base url
$s = new Server ( '/' );
//Tell the server where to find the resources
$s->registerResourceFolder ( SOME_APPLICATION_ROOT .  '/resources', 'name\space\resources' );
$s->registerResourceClass('example\name\space\Resource');
echo $s->serve ();
exit;
``` 
In your base server directory add an .htaccess file with the follwing content
```
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
```
Now you have bootstraped RestLt.

###Creating a resource
 
 A resource in Rest Lite is a class that extends the \restlt\Resource class.
 Each resource can contain methods that respond to multiple GETs, POSTs, PUTs, DELETEs and PATCHs.
 It is important to mention that when you are registering resources with the server you are either registering a resource folder and providing a namespace or a single resource by providing the FQNS to resource class. Providing a FQNS (fully qualified name space) is necessary.
 
 To configure the URI for the resource, you need to setup couple of things.
 All the metadata is configurable via the PHP doc blocks. Examples are shown later.
 
 1. Add the @resourceBaseUri in the class doc block.This will set up the base URI for all methods that will be contained in this resource
    '@resourceBaseUri /user' - note the forward slash at the begining
 2. Add @method to the doc block of the class method. This will tell the server what HTTP method this function will be responding to. For example, `@method POST` or `@method GET` will tell the server that the HTTP method is GET or POST
 3. Add @methodUri value for the method URI. 
    * `@methodUri /` - you can either just add the "/" or omit the annotation 
    * `@methodUri /list` - hard coded example
    * `@methodUri /user/([0-9]+)` - regex example - always add the '()' around the regex
    Note that the full URI for your resource is a combination of the server base URI, that was set during \restlt\Server initialization and the addition of @resourceBaseUri + @methodUri. In general consider the URI as of a regular expression. This is how it is evaluated and followint the preg_match() rules for binding its third parameter, whatever you surround with "()" ends up as a parameter of your method.

For example, if your complete URI ends up to be /account/([0-9]+)/contact/([a-z]+), your method should be accepting 2 parameters. The first of which will be a sequence of digits and the second one letters.
 
A resource can have multiple methods that respond to GET, POST, etc.
 
###A simple resource example
```php
namespace restlt\examples\resources;
/**
 * 
 * @resourceBaseUri /resource1
 */
class Resource1 extends \restlt\Resource {
    public function __construct(\restlt\Request $request, \restlt\Response $response) {
        parent::__construct($request,$resource);
        $f1 = function ($request) {
        };

        $f2 = function ($request,$response,$return) {
        };

        $f3 = function ($request,$response,$e) {
            mail('<EMAIL>', 'Error in resource', $e->getMessage());
        };

        $this->on ( self::ON_BEFORE, 'getMe', $f2 );
        $this->on ( self::ON_AFTER, 'getMe', $f1 );
        $this->on ( self::ON_ERROR, 'getMe', $f3 );
    }
    /**
     * Note that the regex in "()" gets converted to a parameter of the method
     * Since v 1.1.0a this user comment section will appear in a simple HTML format
     * accesible at the root of ther server like this: http://url.com/approot.html
     * @method GET
     * @methodUri /([0-9]+)
     */
    public function getMe($id = '') {
        $obj = new \stdClass ();
        $obj->a = array (9,8,7);
        //obtain the "someParam" - from POST or GET
        $this->request->get ( 'someParam',$defaultValueIfParamIsMissing );
        return $boj;
    }<commit_msg>IM** - remove more complex example<commit_after>##A "thin" REST-full server implementation in PHP 
RestLt is a flexible small library that will allow you to build RESTfull service.
Most of the sub-components are extensible or replaceable. This would let you modify the server's behavior.
Any feedback is appreciated!


[![Build Status](https://travis-ci.org/ivolator/restlt.png)](https://travis-ci.org/ivolator/restlt)
##Installing
###Using Composer
In require section of your composer.json file add the information for RestLt as follows:
```
{ 
        "require" :
        { 
                "restlt/restlt":"1.0.3b"
        }
}
```
Run `composer.phar --dev update`

###Clone with GIT
Use this URL to clone the repo
`https://github.com/ivolator/restlt.git`

##Basics 
###Server end point setup
```php
//Get instance of the server by passing the server base url
$s = new Server ( '/' );
//Tell the server where to find the resources
$s->registerResourceFolder ( SOME_APPLICATION_ROOT .  '/resources', 'name\space\resources' );
$s->registerResourceClass('example\name\space\Resource');
echo $s->serve ();
exit;
``` 
In your base server directory add an .htaccess file with the follwing content
```
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
```
Now you have bootstraped RestLt.

###Creating a resource
 
 A resource in Rest Lite is a class that extends the \restlt\Resource class.
 Each resource can contain methods that respond to multiple GETs, POSTs, PUTs, DELETEs and PATCHs.
 It is important to mention that when you are registering resources with the server you are either registering a resource folder and providing a namespace or a single resource by providing the FQNS to resource class. Providing a FQNS (fully qualified name space) is necessary.
 
 To configure the URI for the resource, you need to setup couple of things.
 All the metadata is configurable via the PHP doc blocks. Examples are shown later.
 
 1. Add the @resourceBaseUri in the class doc block.This will set up the base URI for all methods that will be contained in this resource
    '@resourceBaseUri /user' - note the forward slash at the begining
 2. Add @method to the doc block of the class method. This will tell the server what HTTP method this function will be responding to. For example, `@method POST` or `@method GET` will tell the server that the HTTP method is GET or POST
 3. Add @methodUri value for the method URI. 
    * `@methodUri /` - you can either just add the "/" or omit the annotation 
    * `@methodUri /list` - hard coded example
    * `@methodUri /user/([0-9]+)` - regex example - always add the '()' around the regex
    Note that the full URI for your resource is a combination of the server base URI, that was set during \restlt\Server initialization and the addition of @resourceBaseUri + @methodUri. In general consider the URI as of a regular expression. This is how it is evaluated and followint the preg_match() rules for binding its third parameter, whatever you surround with "()" ends up as a parameter of your method.

For example, if your complete URI ends up to be /account/([0-9]+)/contact/([a-z]+), your method should be accepting 2 parameters. The first of which will be a sequence of digits and the second one letters.
 
A resource can have multiple methods that respond to GET, POST, etc.
 
###A simple resource example
```php
namespace restlt\examples\resources;
/**
 * 
 * @resourceBaseUri /resource1
 */
class Resource1 extends \restlt\Resource {
    /**
     * Note that the regex in "()" gets converted to a parameter of the method
     * Since v 1.1.0a this user comment section will appear in a simple HTML format
     * accesible at the root of ther server like this: http://url.com/approot.html
     * @method GET
     * @methodUri /([0-9]+)
     */
    public function getMe($id = '') {
        $obj = new \stdClass ();
        $obj->a = array (9,8,7);
        //obtain the "someParam" - from POST or GET
        $this->get ( 'someParam',$defaultValueIfParamIsMissing );
        return $boj;
    }
{'fraction_non_alphanumeric': 0.09848058525604952, 'fraction_numerical': 0.005627462014631401, 'mean_word_length': 3.445222611305653, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 23, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3534565', 'n_tokens_mistral': 2565, 'n_tokens_neox': 2446, 'n_words': 1129}