Skip to content

About

Send a single HTTP request that contains multiple Symfony/Laravel Request calls. Once all operations are complete, a consolidated response is passed back to you and the HTTP connection is closed.

Resources

Security policy

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

Lemric Batch Request

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\BatchRequest class is deprecated and will be removed in 3.2. Prefer SymfonyBatchRequestFacade.

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.

About

Send a single HTTP request that contains multiple Symfony/Laravel Request calls. Once all operations are complete, a consolidated response is passed back to you and the HTTP connection is closed.

Resources

Security policy

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages