aef / laravel-batch-requests
A Laravel package for efficiently handling multiple API requests in a single batch operation, reducing network overhead and improving performance for bulk operations.
Installs: 1 358
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/aef/laravel-batch-requests
Requires
- php: ^8.2
- laravel/framework: ^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2025-10-19 11:34:34 UTC
README
A Laravel package for efficiently handling multiple API requests in a single batch operation, reducing network overhead and improving performance for bulk operations.
Installation
You can install the package via composer:
composer require aef/laravel-batch-requests
Configuration
Publish the configuration file:
php artisan vendor:publish --provider="LaravelBatchRequests\BatchRequestServiceProvider" --tag="config"
This will create a config/batch-requests.php file where you can modify the package settings.
Usage
use LaravelBatchRequests\Http\Controllers\BatchRequestController; Route::post('batch', [BatchRequestController::class, 'process']);
To use the batch request functionality, send a POST request to the /api/batch endpoint with a JSON payload containing
an array of requests:
{
"requests": [
{
"id": "get-user",
"method": "GET",
"uri": "/api/users/1",
"headers": {
"Accept": "application/json"
}
},
{
"id": "create-post",
"method": "POST",
"uri": "/api/posts",
"parameters": {
"title": "New Post",
"content": "This is the content of the new post."
},
"headers": {
"Content-Type": "application/json",
"Accept": "application/json"
}
}
]
}
The response will contain the results of all the batched requests, with the body returned as parsed JSON:
{
"results": [
{
"id": "get-user",
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"id": 1,
"name": "John Doe"
}
},
{
"id": "create-post",
"status": 201,
"headers": {
"Content-Type": "application/json"
},
"body": {
"id": 101,
"title": "New Post",
"content": "This is the content of the new post."
}
}
]
}