weckhawk/pretty-response

A fluent and consistent API response builder for Laravel applications.

Maintainers

Package info

github.com/Weckhawk/PrettyResponse

pkg:composer/weckhawk/pretty-response

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-07-27 14:57 UTC

This package is auto-updated.

Last update: 2026-07-30 09:40:27 UTC


README

A fluent, expressive, and consistent API response wrapper for Laravel applications. It helps you standardize JSON responses, handle paginators automatically, and keep your controllers clean.

Features

  • Standardized Structure: Ensures every JSON response follows a predictable format (success, message, data, errors, meta).
  • Smart Pagination Handling: Automatically extracts metadata from Eloquent LengthAwarePaginator, SimplePaginator, and CursorPaginator.
  • Resource Resolution: Seamlessly unwraps Laravel's JsonResource and ResourceCollection.
  • Semantic Named Constructors: Clean static methods like ApiResponse::success(), ApiResponse::validationError(), etc.

Installation

composer require weckhawk/laravel-api-response

Basic Usage

Success Response

use Weckhawk\PrettyResponse\ApiResponse;

return ApiResponse::success(\$users, 'Users fetched successfully');

Paginated Response

Pass any Laravel paginator directly into the success method. The package will automatically append the meta object:

\$paginatedUsers = User::paginate(15);

return ApiResponse::success(\$paginatedUsers);

Error Responses

return ApiResponse::notFound('User not found');

return ApiResponse::validationError([
    'email' => ['The email field is required.']
]);

License

The MIT License (MIT). Please see License File for more information.