f9webltd/laravel-api-response-helpers
Laravel package providing a simple trait to generate consistent JSON API responses across your app. Works with PHP 8.2+ and Laravel 11–13, offering helper methods for common success and error response patterns.
This package provides standardized helper methods for consistent API response formatting in Laravel applications. After installing via Composer (composer require f9webltd/laravel-api-response-helpers), extend your base API controller with F9Web\ApiResponseHelpers\ApiResponseTrait. This exposes core methods like success(), error(), notFound(), and validationError(), along with new HTTP-specific helpers: respondAccepted(), respondConflict(), and respondTooManyRequests().
For first-time use, replace manual response()->json() calls with:
// Standard responses
$this->success(['data' => $model]);
$this->error('Failed', 400);
// New HTTP-specific responses
$this->respondAccepted(); // 202 Accepted
$this->respondConflict('Duplicate entry'); // 409 Conflict
$this->respondTooManyRequests(); // 403 Too Many Requests
{ "status": "success", "data": ..., "message": ... }).respondAccepted()), conflict handling (respondConflict()), and rate-limiting (respondTooManyRequests()).php artisan vendor:publish --tag="api-response-helpers-config") to adjust status keys, messages, or HTTP codes globally.$this->validationError($validator) or wrap Model::firstOrFail() with $this->notFound('Resource not found').respondNoContent() calls with response()->noContent() (RFC 9110 compliance) or await the next major version for a zero-arg wrapper.$data passed to success() is serializable (avoid closures/resources).render() or global reportable callbacks for centralized error logging.respondNoContent() is tagged @deprecated—update code to use response()->noContent() or plan for the next major release’s zero-arg wrapper.config/api-response-helpers.php to align with front-end expectations (e.g., snake_case vs camelCase fields).How can I help you explore Laravel packages today?