<commit_before># Marmelab Silex Multifetch

Multifetch is a Silex provider which add multifetch capabilities to your Silex project. Based on [Facebook's Batch Requests philosophy](https://developers.facebook.com/docs/graph-api/making-multiple-requests).

## Installation

To install Silex Multifetch provider, run the command below and you will get the latest version:

```bash
composer require marmelab/silex-multifetch "~1.0@dev"
```

Enable `HttpFragmentServiceProvider` in your application:

```php
$app->register(new Silex\Provider\HttpFragmentServiceProvider());

$app->register(new Marmelab\Multifetch\MultifetchServiceProvider(), array(
    'multifetch.url' => 'multi', // this is the default value
    'mutltifetch.parallelize' => false, // this is the default value
));
```

## Tests

Run the tests suite with the following commands:

```bash
make install
make test
```

## Usage

Send a request to the route where the provider is listening, passing the requests to fetch as query parameters. For instance, to fetch `/products/1` and `/users` into one HTTP call, make the following request:

```
GET /multi?product=/product/1&all_users=/users HTTP/1.1
```

The provider will call both HTTP resources, and return a response with a composite body once all the requests are fetched:

```json
{ 
    "product": {
        "code":"200",
        "headers":[
            { "name": "Content-Type", "value": "application/json" }
        ],
        "body": "{ id: 1, name: \"ipad2\", stock: 34 }"
    },
    "all_users": {
        "code":"200",
        "headers":[
            { "name": "Content-Type", "value": "application/json" }
        ],
        "body": "[{ id: 2459, login: \"paul\" }, { id: 7473, login: \"joe\" }]"
    }
}
```

Any header present in the multifetch request will be automatically added to all sub-requests.

You can also fetch all requests in parallel using the `_parallel` query parameter:

```
GET /multi?product=/product/1&all_users=/users&_parallel=1 HTTP/1.1
```

You can also, if you want, enable parallel fetching for all queries by setting `'mutltifetch.parallelize'` provider parameter to `true`. But in that case, if you want to disable parallelizing for only one query, you can do:

```
GET /multi?product=/product/1&all_users=/users&_parallel=0 HTTP/1.1
```<commit_msg>Update readme for post route<commit_after># Marmelab Silex Multifetch

Multifetch is a Silex provider which add multifetch capabilities to your Silex project. Based on [Facebook's Batch Requests philosophy](https://developers.facebook.com/docs/graph-api/making-multiple-requests).

## Installation

To install Silex Multifetch provider, run the command below and you will get the latest version:

```bash
composer require marmelab/silex-multifetch "~1.0@dev"
```

Enable `HttpFragmentServiceProvider` in your application:

```php
$app->register(new Silex\Provider\HttpFragmentServiceProvider());

$app->register(new Marmelab\Multifetch\MultifetchServiceProvider(), array(
    'multifetch.url' => 'multi', // this is the default value
    'multifetch.parallel' => false, // this is the default value
));
```

## Tests

Run the tests suite with the following commands:

```bash
make install
make test
```

## Usage

Send a request to the route where the provider is listening, passing the requests to fetch as a JSON object in the request body. For instance, to fetch `/products/1` and `/users` on one HTTP call, make the following request:

```
POST /multi HTTP/1.1
Content-Type: application/json
{
    "product": "/products/1",
    "all_users": "/users"
}
```

The provider will call both HTTP resources, and return a response with a composite body once all the requests are fetched:

```json
{ 
    "product": {
        "code":"200",
        "headers":[
            { "name": "Content-Type", "value": "application/json" }
        ],
        "body": "{ id: 1, name: \"ipad2\", stock: 34 }"
    },
    "all_users": {
        "code":"200",
        "headers":[
            { "name": "Content-Type", "value": "application/json" }
        ],
        "body": "[{ id: 2459, login: \"paul\" }, { id: 7473, login: \"joe\" }]"
    }
}
```

Any header present in the multifetch request will be automatically added to all sub-requests.

You can also fetch all requests in parallel using the `_parallel`  parameter:

```
POST /multi HTTP/1.1
Content-Type: application/json
{
    "product": "/products/1",
    "all_users": "/users",
    "_parallel": true
}
```

You can also, if you want, enable parallel fetching for all queries by setting `'mutltifetch.parallel'` provider parameter to `true`. But in that case, if you want to disable parallelizing for only one query, you can do:

```
POST /multi HTTP/1.1
Content-Type: application/json
{
    "product": "/products/1",
    "all_users": "/users",
    "_parallel": false
}
```

**Tip**: a GET route is available, the provider reads the query parameters to determine requests to fetch:

```
GET /multi?product=/product/1&all_users=/users&_parallel=1 HTTP/1.1
```
{'fraction_non_alphanumeric': 0.13254698120751698, 'fraction_numerical': 0.013194722111155539, 'mean_word_length': 3.7466793168880455, 'pattern_counts': {'":': 32, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4903561', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1483, 'n_words': 536}