<commit_before># RREST

**RREST** helps to build good REST API in PHP.

> Important: **RREST** is in active development. The API is not frozen and BC break can happen at any time.

**RREST** do the glue between an [API specification language](https://en.wikipedia.org/wiki/Overview_of_RESTful_API_Description_Languages) (APISpec) like RAML, Swagger... and a router/framework (Provider) in charge of routing the request like [Silex](http://silex.sensiolabs.org/), [Symfony](https://symfony.com/), [Laravel](https://laravel.com/)... to your business logic.


**RREST** take care of boring stuff to make a good REST API:
* query parameters validation
* `Accept` header validation
* `Content-Type` validation
* protocol validation
* request payload body validation with [JSON Schema](http://json-schema.org/) or [XMLSchema](https://www.w3.org/XML/Schema)
* response with the right HTTP Status code
* parameters & payload body hinted (only for JSON)
* pre-formated response object (header configured) and automatic serialization
* automatic binding with a Controller, by convention:
    * POST /item/ -> `Controllers\Item#postAction`
    * GET /item/{itemId}/ -> `Controllers\Item#getAction`
    * GET /item/{itemId}/comment -> `Controllers\Item\Comment#getAction`
    * PUT /item/{itemId}/comment/{commentId} -> `Controllers\Item\Comment#putAction`

## Use case

I need to add a new resource in my API:
* update the API specification with new resource and all parameters, headers... needed.
* create the Controller for the resource

That's all, you're resource if ready to use:
* the route is ready
* the validations are ready
* the response is ready

What you need to do is your job: **making the business logic**.

## Installation

> **RREST** is in active development and not available in [packagist](https://packagist.org).

Manualy update your composer.json file:

```json
"repositories": [
    {
        "type": "git",
        "url": "https://github.com/RETFU/RREST"
    }
],
"require": {
    "retfu/rrest": "dev-master"
}
```

```bash
$ composer update
```

<!-- The recommended way to install **RREST** is through [Composer](https://getcomposer.org/):

```bash
$ composer require retfu/rrest
``` -->

## Usage

Silex + RAML

```php
<?php

$ramlFile = 'api.raml';

$app = new Silex\Application();

//more application logic here if needed

//parse the RAML file
$apiDefinition = (new Raml\Parser())->parse($ramlFile, true);
//load a RAML APISPec by injecting the RAML Parser instance
$apiSpec = new APISpec\RAML($apiDefinition);
//load a Silex Provider by injecting the Silex app instance
$provider = new Provider\Silex($app);
//bind APISpec + Provider
$rrest = new RREST\RREST($apiSpec, $provider, 'Controllers');
//add only the current route if match the APISpec
//validate `Accept`, `Content-Type`, protocol
$rrest->addRoute();

//more application logic here if needed

$app->run();
//after app apply routing logic, validate parameters and body payload against the APISpec
//hint parameters & body payload (only for JSON)
    ```

## Support

Format input/output
* JSON
* XML

APISPec
* RAML
* More coming soon

Provider
* Silex
* More coming soon

## Why RREST

All those projects make an **amazing work**:<commit_msg>doc: fix typo in README<commit_after># RREST

**RREST** helps to build good REST API in PHP.

> Important: **RREST** is in active development. The API is not frozen and BC break can happen at any time.

**RREST** do the glue between an [API specification language](https://en.wikipedia.org/wiki/Overview_of_RESTful_API_Description_Languages) (APISpec) like RAML, Swagger... and a router/framework (Provider) in charge of routing the request like [Silex](http://silex.sensiolabs.org/), [Symfony](https://symfony.com/), [Laravel](https://laravel.com/)... to your business logic.


**RREST** take care of boring stuff to make a good REST API:
* query parameters validation
* `Accept` header validation
* `Content-Type` validation
* protocol validation
* request payload body validation with [JSON Schema](http://json-schema.org/) or [XMLSchema](https://www.w3.org/XML/Schema)
* response with the right HTTP Status code
* parameters & payload body hinted (only for JSON)
* pre-formated response object (header configured) and automatic serialization
* automatic binding with a Controller, by convention:
    * POST /item/ -> `Controllers\Item#postAction`
    * GET /item/{itemId}/ -> `Controllers\Item#getAction`
    * GET /item/{itemId}/comment -> `Controllers\Item\Comment#getAction`
    * PUT /item/{itemId}/comment/{commentId} -> `Controllers\Item\Comment#putAction`

## Use case

I need to add a new resource in my API:
* update the API specification with new resource and all parameters, headers... needed.
* create the Controller for the resource

That's all, you're resource if ready to use:
* the route is ready
* the validations are ready
* the response is ready

What you need to do is your job: **making the business logic**.

## Installation

> **RREST** is in active development and not available in [packagist](https://packagist.org).

Manualy update your composer.json file:

```json
"repositories": [
    {
        "type": "git",
        "url": "https://github.com/RETFU/RREST"
    }
],
"require": {
    "retfu/rrest": "dev-master"
}
```

```bash
$ composer update
```

<!-- The recommended way to install **RREST** is through [Composer](https://getcomposer.org/):

```bash
$ composer require retfu/rrest
``` -->

## Usage

Silex + RAML

```php
<?php

$ramlFile = 'api.raml';

$app = new Silex\Application();

//more application logic here if needed

//parse the RAML file
$apiDefinition = (new Raml\Parser())->parse($ramlFile, true);
//load a RAML APISPec by injecting the RAML Parser instance
$apiSpec = new APISpec\RAML($apiDefinition);
//load a Silex Provider by injecting the Silex app instance
$provider = new Provider\Silex($app);
//bind APISpec + Provider
$rrest = new RREST\RREST($apiSpec, $provider, 'Controllers');
//add only the current route if match the APISpec
//validate `Accept`, `Content-Type`, protocol
$rrest->addRoute();

//more application logic here if needed

$app->run();
//after app apply routing logic, validate parameters and body payload against the APISpec
//hint parameters & body payload (only for JSON)
```

## Support

Format input/output
* JSON
* XML

APISPec
* RAML
* More coming soon

Provider
* Silex
* More coming soon

## Why RREST

All those projects make an **amazing work**:
{'fraction_non_alphanumeric': 0.12906724511930587, 'fraction_numerical': 0.0003098853424233034, 'mean_word_length': 4.218270008084074, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 14, 'lorem ipsum': 0, 'www.': 2, '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': '3561402', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1936, 'n_words': 721}