api-responder-for-laravel maintained by pepperfm
Description
Easy api responder template using via DI
Author
Last update
2026/03/17 11:58
(3.x-dev)
License
Downloads
1 582
Tags
Last update
2026/03/17 11:58
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
Last update
2026/03/17 09:28
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
Last update
2026/03/16 23:49
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
Last update
2025/05/26 00:04
License
Require
- php ^8.2
- guzzlehttp/psr7 ^2.6
- guzzlehttp/guzzle ^7.9
Last update
2025/05/26 00:03
License
Require
- php ^8.2
- guzzlehttp/psr7 ^2.6
- guzzlehttp/guzzle ^7.9
Last update
2025/05/26 00:03
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
Last update
2025/05/24 19:11
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
Last update
2025/01/24 23:39
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2025/01/24 23:34
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2025/01/24 23:31
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2025/01/23 21:04
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2025/01/23 20:52
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2025/01/23 20:29
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2025/01/23 20:29
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2025/01/23 19:46
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/08/05 00:02
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/08/04 23:12
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/29 18:28
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/29 11:30
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/20 17:03
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.9
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/19 12:08
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/18 23:05
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/17 23:55
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/17 23:32
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/17 21:15
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/08 22:26
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/08 22:26
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/08 21:42
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/08 21:36
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/08 14:14
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/06 22:23
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/07/06 22:12
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/04/18 19:19
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/03/15 20:18
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/03/15 20:08
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/03/15 20:06
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/03/15 18:24
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/03/15 18:22
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/03/14 20:25
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/03/14 19:57
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/03/14 17:19
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database >=10.0
- illuminate/http >=10.0
- illuminate/support >=10.0
Last update
2024/03/13 23:01
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database ^10.0
- illuminate/http ^10.0
- illuminate/support ^10.0
Last update
2024/03/13 22:58
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database ^10.0
- illuminate/http ^10.0
- illuminate/support ^10.0
Last update
2024/03/13 22:44
License
Require
- php ^8.2
- guzzlehttp/guzzle ^7.8
- guzzlehttp/psr7 ^2.6
- illuminate/database ^10.0
- illuminate/http ^10.0
- illuminate/support ^10.0
Last update
2023/05/05 09:20
License
Require
- php ^8.1
- illuminate/database *
- illuminate/http *
- illuminate/support *
Last update
2023/05/02 19:44
License
Require
- php ^8.2
- illuminate/database *
- illuminate/http *
- illuminate/support *
Last update
2023/05/02 19:41
License
Require
- php ^8.2
- illuminate/database ^9
- illuminate/http ^9
- illuminate/support ^9
Last update
2023/05/02 19:39
License
Require
- php ^8.2
- illuminate/database 9.*
- illuminate/http 9.*
- illuminate/support 9.*
Last update
2023/05/02 19:32
License
Require
- php ^8.2
- illuminate/database ^9.5
- illuminate/http ^9.5
- illuminate/support ^9.5
Last update
2023/04/29 22:17
License
Require
- php ^8.2
- illuminate/database ^10.9.0
- illuminate/http ^10.9.0
- illuminate/support ^10.9.0
Last update
2023/04/29 22:13
License
Require
- php ^8.2
- illuminate/database ^10.9.0
- illuminate/http ^10.9.0
- illuminate/support ^10.9.0
Last update
2023/04/29 22:03
License
Require
- php ^8.2
- illuminate/database ^10.9.0
- illuminate/http ^10.9.0
- illuminate/support ^10.9.0
Last update
2023/04/29 21:55
License
Require
- php ^8.2
- illuminate/database ^10.9.0
- illuminate/http ^10.9.0
- illuminate/support ^10.9.0
Last update
2023/04/29 21:49
License
Require
- php ^8.2
- illuminate/database ^10.9.0
- illuminate/http ^10.9.0
- illuminate/support ^10.9.0
Last update
2023/04/29 21:49
License
Require
- php ^8.2
- illuminate/database ^10.9.0
- illuminate/http ^10.9.0
- illuminate/support ^10.9.0
Last update
2023/04/29 21:47
License
Require
- php ^8.2
- illuminate/database ^10.9.0
- illuminate/http ^10.9.0
- illuminate/support ^10.9.0
Last update
2023/04/29 21:44
License
Require
- php ^8.2
- illuminate/database ^10.9.0
- illuminate/http ^10.9.0
- illuminate/support ^10.9.0
Last update
2023/04/29 21:14
License
Require
- php ^8.2
- illuminate/database ^10.9.0
- illuminate/http ^10.9.0
- illuminate/support ^10.9.0
Last update
2023/04/29 19:01
License
Require
- php ^8.2
- illuminate/database ^10.9.0
- illuminate/http ^10.9.0
- illuminate/support ^10.9.0
Last update
2023/04/29 00:58
License
Require
- php ^8.2
- illuminate/database ^10.9.0
- illuminate/http ^10.9.0
- illuminate/support ^10.9.0
Last update
2023/04/29 00:47
License
Require
- php ^8.2
- illuminate/database ^10.9.0
- illuminate/http ^10.9.0
- illuminate/support ^10.9.0
Last update
2023/04/29 00:40
License
Require
- php ^8.2
- illuminate/database ^10.9.0
- illuminate/http ^10.9.0
- illuminate/support ^10.9.0
Last update
2023/04/28 23:53
License
Require
- php ^8.2
- illuminate/database ^10.9.0
- illuminate/http ^10.9.0
- illuminate/support ^10.9.0
Last update
2023/04/28 22:49
License
Require
- php ^8.2
- illuminate/database ^10.9
- illuminate/http ^10.9
- illuminate/support ^10.9
Api responder for Laravel

Standardized API JSON responses for Laravel
[!TIP] Full Package Description: Helpful advice for doing things better or more easily.
Installation
composer require pepperfm/api-responder-for-laravel
Usage
Inject via Laravel DI
use Pepperfm\ApiBaseResponder\Contracts\ResponseContract;
class UserController extends Controller
{
public function __construct(public ResponseContract $json)
{
}
}
Direct API (config-based data key)
The simplest approach — data key and wrapping are resolved from config:
public function index(Request $request)
{
$users = User::query()->whereIn('id', $request->input('ids'))->get();
return $this->json->response($users->toArray());
}
public function store(StoreUserRequest $request)
{
$user = User::create($request->validated());
return $this->json->stored($user->toArray());
}
public function destroy(User $user)
{
$user->delete();
return $this->json->deleted();
}
Builder API (explicit control)
Use the fluent builder when you need per-response control over data keys or wrapping:
// Explicit data key
public function index()
{
$users = User::all();
return $this->json->withDataKey('users')->response($users->toArray());
}
// REST method convention (singular key for show/update, plural for index/etc.)
public function show(User $user)
{
return $this->json->forMethod('show')->response($user->toArray());
}
// Disable wrapping (data spread into response root)
public function stats()
{
return $this->json->build()->withoutWrapping()->response($stats);
}
PHP Attributes (declarative style)
Use #[ResponseDataKey] and #[WithoutWrapping] attributes with fromAction():
use Pepperfm\ApiBaseResponder\Attributes\ResponseDataKey;
use Pepperfm\ApiBaseResponder\Attributes\WithoutWrapping;
#[ResponseDataKey('user')]
public function show(User $user): JsonResponse
{
return $this->json->fromAction()->response($user->toArray());
}
#[ResponseDataKey] // defaults to singular 'entity'
public function edit(User $user): JsonResponse
{
return $this->json->fromAction()->response($user->toArray());
}
#[WithoutWrapping]
public function stats(): JsonResponse
{
return $this->json->fromAction()->response($stats);
}
Pagination
public function index(Request $request)
{
$users = User::query()->paginate();
return $this->json->paginated($users);
}
// With data mapping
public function index(Request $request)
{
$users = User::query()->paginate();
$dtoCollection = $users->getCollection()->mapInto(UserDto::class);
return $this->json->paginated($dtoCollection->toArray(), $users);
}
Error responses
return $this->json->error('Not found', 404);
return $this->json->error('Validation failed', 422, $validator->errors());
Facades
use Pepperfm\ApiBaseResponder\Facades\BaseResponse;
return BaseResponse::response($data);
return BaseResponse::forMethod('index')->response($data);
return BaseResponse::fromAction()->response($data);
Method injection / resolve
public function index(Request $request, ResponseContract $json)
{
return $json->response($users->toArray());
}
// or
return resolve(ResponseContract::class)->response($users->toArray());
Paginated response format
The pagination meta is extracted automatically from LengthAwarePaginator or CursorPaginator:
export interface IPaginatedResponse<T> {
current_page: number
per_page: number
last_page: number
data: T[]
from: number
to: number
total: number
prev_page_url?: any
next_page_url: string
links: IPaginatedResponseLinks[]
}
export interface IPaginatedResponseLinks {
url?: any
label: string
active: boolean
}
Configuration
Publish the config file:
php artisan vendor:publish --provider="Pepperfm\ApiBaseResponder\Providers\ApiBaseResponderServiceProvider" --tag="config"
Key options:
plural_data_key— data key for collections (default:'entities')singular_data_key— data key for single items (default:'entity')without_wrapping— disable data-key wrapping globally (default:false)using_for_rest— enable REST method-based key resolution (default:true)methods_for_singular_key— methods that use singular key (default:['show', 'update'])force_json_response_header— auto-addAccept: application/jsonto API requests (default:true)
Check the configuration file to customize response wrapping as you prefer
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email Damon3453@yandex.ru instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.