Download the PHP package anyo-lab/api-response without Composer
On this page you can find all versions of the php package anyo-lab/api-response. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download anyo-lab/api-response
More information about anyo-lab/api-response
Files in anyo-lab/api-response
Package api-response
Short Description A Laravel package for universal API response and error handling
License MIT
Homepage https://github.com/laravel-api-response/api-response
Informations about the package api-response
Laravel API Response
A comprehensive Laravel package for universal API response and error handling. This package provides a standardized way to format API responses and handle exceptions in Laravel applications with multiple usage patterns and advanced features.
π Features
- π― Standardized API Responses - Consistent response format across your entire API
- π‘οΈ Automatic Exception Handling - Custom exception handler for API routes
- π Multiple Usage Methods - Use as service, trait, facade, macros, or helper functions
- βοΈ Highly Configurable - Customize response structure and messages
- π Built-in Pagination - Automatic pagination response formatting
- π§ Laravel 9-12 Support - Compatible with multiple Laravel versions
- π― Resource Classes - Built-in resource transformation classes
- π Response Macros - Extend Laravel's response with API methods
- π Global Helpers - Easy-to-use global helper functions
- π οΈ Middleware Support - Automatic response formatting middleware
- π¦ Rate Limiting Integration - Formatted rate limiting responses
- π¦ Response Compression - Automatic response compression (gzip, deflate)
- π API Versioning - Built-in API versioning support
- π Performance Monitoring - Response performance tracking
π Requirements
- PHP >= 8.1
- Laravel >= 9.0
π§ Installation
Via Composer
Manual Installation
- Clone or download this package
-
Add to your
composer.json: - Run
composer update
βοΈ Configuration
Publish the configuration file:
This will create config/api-response.php with customizable options.
Production readiness
Before using in a live project:
- Set
APP_DEBUG=falsein.envso error responses never expose stack traces or file paths. - Publish config (optional):
php artisan vendor:publish --tag=api-response-configto override messages, structure, or timestamp format. - Override messages in
config/api-response.phpundermessagesso all default strings (e.g. "Resource not found") come from one place. - Optional: Enable
include_request_idandinclude_error_codesin config for tracing and machine-readable error codes.
All responses use the same config (structure, timestamp, error codes). ResponseHelper and resources use the same settings as the main ApiResponse service.
Upgrading / Breaking changes
-
Response caching removed: The package no longer provides
api_cache(),api_remember(), orApiResponseCache. For cached API responses, use LaravelβsCache::remember()withapi_success(): - 204 No Content:
noContent()now returns an empty response body (RFC 7231) instead of a JSON body. - Performance monitoring optional: Set
register_performance_monitoringtofalsein config to disable cache usage when you do not useapi_performance().
See CHANGELOG.md for full version history.
π― Quick Start
Basic Usage
Tip: For testability and flexibility, type-hint ApiResponseContract instead of ApiResponse so you can swap or mock the implementation.
π Usage Methods
Method 1: Service Injection
Method 2: Trait Usage
Method 3: Facade Usage
Method 4: Response Macros
Method 5: Global Helper Functions
Method 6: Resource Classes
π€ Response Methods
Success Responses
Error Responses
π Response Format
All responses follow this standardized format:
Success Response
Error Response
Pagination Response
π‘οΈ Exception Handling
The package includes a custom exception handler that automatically formats exceptions for API routes:
| Exception | Status Code | Description |
|---|---|---|
ValidationException |
422 | Validation errors |
AuthenticationException |
401 | Unauthorized |
ModelNotFoundException |
404 | Not found |
NotFoundHttpException |
404 | Not found |
QueryException |
500 | Server error (with debug info in development) |
HttpException |
Respective | HTTP status code |
βοΈ Configuration Options
Response Structure
Default Messages
Other Options
π Advanced Features
Middleware Support
API Versioning
Response Compression
Performance Monitoring
π§ͺ Testing
π Complete Example
Testing this package
Enterprise & production
For production use, enable request IDs and error codes in config; apply rate limiting and set APP_DEBUG=false.
π€ Contributing
Please see CONTRIBUTING.md for development setup, code style, and pull request guidelines.
Security
If you discover a security vulnerability, please see SECURITY.md.
Changelog
See CHANGELOG.md for version history.
π License
This package is open-sourced software licensed under the MIT license.
π Support
- Issues: GitHub Issues
- Documentation: Full Documentation
π Acknowledgments
- Laravel team for the amazing framework
- All contributors who help improve this package
- The open-source community for inspiration and feedback
Laravel API Response β A generic package for standardized API responses.
All versions of api-response with dependencies
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
illuminate/http Version ^9.0|^10.0|^11.0|^12.0
illuminate/validation Version ^9.0|^10.0|^11.0|^12.0
illuminate/cache Version ^9.0|^10.0|^11.0|^12.0