lemric/batch-request
| Install | |
|---|---|
composer require lemric/batch-request |
|
| Latest Version: | 3.1.4 |
| PHP: | >=8.2 |
| License: | MIT |
| Last Updated: | Oct 10, 2026 |
| Links: | GitHub · Packagist |
Lemric Batch Request
Batch HTTP API calls into a single request. Compatible with Symfony 6.4+ / 7 / 8 and Laravel 10+.
Send one JSON envelope containing multiple operations. Independent read-only operations may run in parallel (PHP Fibers); write operations stay serialised. When every operation finishes, a consolidated JSON response is returned and the HTTP connection is closed.
Requirements
| Requirement | Version |
|---|---|
| PHP | ≥ 8.2 |
| Symfony* | ^6.4 | ^7 | ^8 |
| Laravel* | ^10 | ^11 | ^12 |
* Framework packages are optional — install only the bridge you need. See Installation.
Installation
composer require lemric/batch-request
Quick Start
Symfony
// config/bundles.php
return [
// ...
Lemric\BatchRequest\Bridge\Symfony\BatchRequestBundle::class => ['all' => true],
];
use Lemric\BatchRequest\Bridge\Symfony\SymfonyBatchRequestFacade;
use Symfony\Component\HttpFoundation\{Request, Response};
use Symfony\Component\Routing\Attribute\Route;
#[Route('/batch', name: 'batch', methods: ['POST'])]
public function batch(Request $request, SymfonyBatchRequestFacade $batch): Response
{
return $batch->handle($request);
}
Note: The legacy
Lemric\BatchRequest\BatchRequestclass is deprecated and will be removed in 3.2. PreferSymfonyBatchRequestFacade.
Laravel
// bootstrap/providers.php (Laravel 11+) or config/app.php
Lemric\BatchRequest\Bridge\Laravel\LaravelServiceProvider::class,
use Illuminate\Http\{JsonResponse, Request};
use Lemric\BatchRequest\Bridge\Laravel\LaravelBatchRequestFacade;
public function __invoke(Request $request, LaravelBatchRequestFacade $batch): JsonResponse
{
return $batch->handle($request);
}
Example request
curl -X POST https://example.com/batch \
-H 'Content-Type: application/json' \
-d '[
{"method":"GET","relative_url":"/api/users/1"},
{"method":"GET","relative_url":"/api/users/2"},
{"method":"POST","relative_url":"/api/posts","body":{"title":"Hello"}}
]'
Example response
[
{"code": 200, "body": {"id": 1, "name": "Alice"}},
{"code": 200, "body": {"id": 2, "name": "Bob"}},
{"code": 201, "body": {"id": 42, "title": "Hello"}}
]
The order of responses always matches the order of operations.
Documentation
| Topic | Description |
|---|---|
| Installation | Composer setup, optional dependencies |
| Usage | Request / response protocol |
| Responses | Content types, binary payloads, headers |
| Errors | Sub-request failures & top-level errors |
| Security | Hardening model & threat mitigations |
| Architecture | Handler, Fibers, validators |
| Symfony integration | Bundle, configuration, profiler, rate limiting |
| Laravel integration | Service provider, configuration, controller |
Full table of contents: docs/index.md.
Features
- Framework bridges for Symfony (
BatchRequestBundle) and Laravel - Fiber-based concurrency for contiguous read-only (
GET/HEAD) groups, with bounded concurrency - OWASP-oriented validation (path traversal, CRLF, SSRF, recursive batches, header injection)
- RFC 7807 problem documents for failed sub-responses and top-level errors
- Mixed media types in one batch (JSON, HTML, XML, binary/base64,
BinaryFileResponse,StreamedResponse) - Symfony Web Profiler panel (dev)
- Optional rate limiting via
symfony/rate-limiter
Security
If you discover a security vulnerability, please follow the process described in SECURITY.md. Do not open a public issue.
Contributing
- Run the test suite:
composer test - Static analysis:
composer analyse - Bug reports and pull requests are welcome on GitHub.
License
This package is released under the MIT license.
Related Packages
Light weight curl request library by http://www.codeitnow.in, It has setters and...
Version History
| Version | Released | PHP | License |
|---|---|---|---|
| 3.1.4 | >=8.2 | MIT | |
| 3.1.3 | >=8.2 | MIT | |
| 3.1.2 | >=8.2 | GPL-3.0-or-later | |
| 3.1.1 | >=8.2 | GPL-3.0-or-later | |
| 3.1.0 | >=8.2 | GPL-3.0-or-later | |
| 3.0.2 | >=8.2 | GPL-3.0-or-later | |
| 3.0.1 | >=8.2 | GPL-3.0-or-later | |
| 3.0.0 | >=8.2 | GPL-3.0-or-later | |
| 2.1.4 | >=8.1 | GPL-3.0-or-later | |
| 2.1.3 | >=8.1 | GPL-3.0-or-later | |
| 2.1.2 | >=8.1 | GPL-3.0-or-later | |
| 2.0.7 | >=8.1 | GPL-3.0-or-later | |
| 2.0.6 | >=8.1 | GPL-3.0-or-later | |
| 2.0.0 | >=8.1 | GPL-3.0-or-later | |
| 1.1.6 | >=8.1 | GPL-3.0-or-later | |
| 1.1.5 | >=8.1 | GPL-3.0-or-later | |
| 1.1.4 | >=8.1 | GPL-3.0-or-later | |
| 1.1.3 | >=8.1 | GPL-3.0-or-later | |
| 1.1.2 | >=8.1 | GPL-3.0-or-later | |
| 1.1.1 | >=8.1 | GPL-3.0-or-later | |
| 1.1.0 | >=8.1 | GPL-3.0-or-later | |
| 1.0.1 | GPL-3.0-or-later | ||
| 1.0.0 | GPL-3.0-or-later |