Download the PHP package aliziodev/laravel-api-response without Composer
On this page you can find all versions of the php package aliziodev/laravel-api-response. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-api-response
Laravel API Response
A standardized API Response package for Laravel with Responsable
implementation. This package provides a consistent way to structure your API responses across your Laravel application.
Features
- Standardized API Response format
- Built-in support for success, error, and fail responses
- Automatic error reference generation
- Sensitive data masking in logs
- Debug information for development
- Laravel's
Responsable
interface implementation - Type-safe implementation with strict types
- Comprehensive test coverage
Installation
You can install the package via Composer:
Usage
Basic Usage
Exception Handling
For Laravel 11, you need to register the exception handler in bootstrap/app.php
:
This setup will handle all exceptions for JSON requests and return standardized API responses. The handler will:
- Automatically detect exception types
- Generate reference codes for errors
- Mask sensitive data in logs
- Include debug information in non-production environments
- Return appropriate HTTP status codes
- Format error messages consistently
Common exceptions that are handled:
- Authentication exceptions (401)
- Authorization exceptions (403)
- Validation exceptions (422)
- Not found exceptions (404)
- Database exceptions (500)
- Rate limiting exceptions (429)
- Service unavailable exceptions (503)
Response Types
Success Responses
Error Responses
Fail Responses
Response Format
Success Response
Error Response
Fail Response
Logging
The package automatically logs errors and failures with sensitive data masking:
Testing
Static Analysis
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Alizio
- All Contributors
License
The MIT License (MIT). Please see License File for more information.