stackmasteraliza/laravel-api-response
phpstan/phpstan: ^1.10|^2.0larastan/larastan: ^2.0|^3.0| PHP | Laravel 10 | Laravel 11 | Laravel 12 |
|---|---|---|---|
| 8.1 | ✅ | - | - |
| 8.2 | ✅ | ✅ | ✅ |
| 8.3 | ✅ | ✅ | ✅ |
Full Changelog: https://github.com/stackmasteraliza/laravel-api-response/compare/v4.0.0...v4.7.0
Full Changelog: https://github.com/stackmasteraliza/laravel-api-response/compare/v3.9.1...v4.1.0
A comprehensive Laravel package for building standardized JSON API responses with zero-configuration OpenAPI/Swagger documentation. Features include fluent response building, automatic pagination metadata, built-in exception handling, validation error formatting, API versioning support, WebSocket testing, and export capabilities to Postman and Insomnia. Compatible with Laravel 10, 11, and 12.
Full Changelog: https://github.com/stackmasteraliza/laravel-api-response-builder/compare/v3.8.0...v3.9.0
/api/v1, /api/v2, etc.)Config
'versioning' => [
'enabled' => env('API_DOCS_VERSIONING', false),
'auto_detect' => true,
],
Config
'websocket' => [
'enabled' => env('API_DOCS_WEBSOCKET', true),
'url' => env('WEBSOCKET_URL', 'ws://localhost:6001'),
],
Full Changelog: https://github.com/stackmasteraliza/laravel-api-response-builder/compare/3.7.0...3.8.0
You can now export API documentation directly from the Swagger UI. With a single click, the API documentation can be downloaded in multiple formats, making it easy to import into your preferred API testing and documentation tools.
A new Export button has been added to the documentation header, providing quick access to all available export options.
Full Changelog: https://github.com/stackmasteraliza/laravel-api-response-builder/compare/v2.9.9...v3.0.0
This release introduces a fully automatic OpenAPI 3.0 documentation system with a modern, customizable dark-theme Swagger UI.
API documentation is generated directly from Laravel routes with zero configuration — no PHP attributes, annotations, or manual schema definitions required. Request and response schemas are inferred automatically from FormRequest classes, ensuring the documentation stays in sync with the codebase.
GET /api-docs — Interactive Swagger UIGET /api-docs/openapi.json — Raw OpenAPI specificationThis release significantly upgrades the package from a response helper to a self-documenting API solution suitable for production use.
This release introduces automatic OpenAPI 3.0 documentation generation with zero configuration. All API routes are scanned automatically, and interactive Swagger documentation is available instantly — no manual annotations or setup required.
Simply visit /api-docs to explore and test your API using the built-in Swagger UI.
Zero-config documentation Instantly generate API docs without writing schemas or YAML files
Interactive Swagger UI
Built-in Swagger interface available at /api-docs for exploring and testing endpoints
CLI support Generate a static OpenAPI JSON file using:
php artisan api:docs
PHP 8 Attributes (optional) Enhance endpoints with summaries, descriptions, tags, parameters, request bodies, and responses
Built-in response schemas Includes standard schemas such as:
SuccessResponseErrorResponsePaginatedResponseValidationErrorResponseFully configurable Customize documentation title, version, routes, UI theme, servers, and security schemes via configuration
composer require stackmasteraliza/laravel-api-response
Open documentation:
http://your-app.com/api-docs
Generate static documentation:
php artisan api:docs
Developers may optionally enhance documentation using PHP 8 attributes:
#[ApiEndpoint(
summary: 'List all users',
description: 'Retrieve a paginated list of users',
tags: ['Users']
)]
#[ApiResponse(status: 200, description: 'Success', ref: 'PaginatedResponse')]
public function index(): JsonResponse
{
return ApiResponse::success(User::paginate(15));
}
#[ApiEndpoint] – Summary, description, tags, deprecation#[ApiRequest] – Query and path parameters#[ApiRequestBody] – Request body schema#[ApiResponse] – Response status, description, examples// config/api-response.php
'openapi' => [
'enabled' => true,
'title' => 'API Documentation',
'version' => '1.0.0',
'docs_route' => 'api-docs',
'theme_color' => '#3b82f6',
],
src/Attributes/ — PHP 8 attributes for API documentationsrc/OpenApi/OpenApiGenerator.php — OpenAPI spec generatorsrc/Console/GenerateApiDocsCommand.php — Artisan commandsrc/Http/Controllers/SwaggerController.php — Swagger UI controllerhttps://github.com/stackmasteraliza/laravel-api-response-builder/compare/v1.3.0...v1.4.0
This release adds three powerful features to enhance extensibility, modern pagination support, and developer testing experience.
Define reusable custom response types using Laravel's Macroable trait:
// In AppServiceProvider boot()
ApiResponse::macro('banned', function ($reason = 'Account suspended') {
return $this->error($reason, 403);
});
// Usage
return ApiResponse::banned('Your account has been suspended');
This release introduces full support for Laravel’s cursor-based pagination, providing significantly better performance for large datasets.
Usage
$users = User::cursorPaginate(15);
return ApiResponse::success($users);
Response Structure
{
"status_code": 200,
"success": true,
"message": "Success",
"data": [],
"meta": {
"per_page": 15,
"next_cursor": "eyJpZCI6MTUuLi4",
"prev_cursor": null,
"path": "http://example.com/api/users",
"links": {
"next": "http://example.com/api/users?cursor=eyJpZCI6MTUuLi4",
"prev": null
}
}
}
Cursor pagination enables efficient navigation without offset-based performance degradation.
New testing assertion macros have been added to simplify API response testing and improve test readability.
Example
$response = $this->getJson('/api/users');
$response->assertApiSuccess()
->assertApiStatusCode(200)
->assertApiMessage('Users retrieved successfully')
->assertApiHasData()
->assertApiPaginated();
assertApiSuccess() – Assert success === trueassertApiError($statusCode = null) – Assert success === false with optional statusassertApiStatusCode($code) – Assert status code in response bodyassertApiMessage($message) – Assert response messageassertApiHasData($key = null) – Assert data existsassertApiDataCount($count) – Assert number of data itemsassertApiData($expected) – Assert full data matchassertApiDataContains($expected) – Assert partial data matchassertApiPaginated() – Assert pagination metadata existsassertApiCursorPaginated() – Assert cursor pagination metadata existsassertApiHasErrors($key = null) – Assert error keys existsrc/ApiResponse.php — Added Macroable trait and cursor pagination supportsrc/ApiResponseServiceProvider.php — Registered testing macrossrc/Facades/ApiResponse.php — Added PHPDoc for macro methodssrc/Testing/ApiResponseAssertions.php — New testing assertions (11 methods)README.md — Updated documentationhttps://github.com/stackmasteraliza/laravel-api-response-builder/compare/v1.2.0...v1.3.0
This release adds the HTTP status code directly in the JSON response body, making it easier for API clients to access response metadata.
{
"status_code": 200,
"success": true,
"message": "Success",
"data": {...}
}
A clean, fluent, and consistent API response builder for Laravel 10/11/12.
Features
Requirements
Installation
composer require stackmasteraliza/laravel-api-response
Quick Start
use Stackmasteraliza\ApiResponse\Facades\ApiResponse;
// Success response
return ApiResponse::success($data, 'Operation successful');
// Error response
return ApiResponse::error('Something went wrong', 400);
License MIT
How can I help you explore Laravel packages today?