Download the PHP package rawnoq/laravel-api-response without Composer
On this page you can find all versions of the php package rawnoq/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 professional Laravel package for standardized API responses with customizable keys and helper functions.
๐ฆ Installation
Install the package via Composer:
The package will automatically register its service provider.
๐ Features
- Standardized API Responses: Consistent JSON response structure across your application
- Customizable Keys: Configure response keys (status, data, message, etc.)
- Helper Function: Easy-to-use
respond()helper function - Pagination Support: Automatic pagination handling for paginated resources
- HTTP Status Codes: Pre-built methods for common HTTP status codes
- Flexible Messages: Support for single messages or arrays of messages
- Type-Safe: Full type hints and return types
๐ Usage
Basic Usage
Helper Function
The package provides a global respond() helper function:
HTTP Status Codes
The package provides pre-built methods for common HTTP status codes:
Pagination Support
The package automatically handles paginated resources:
This will automatically include pagination metadata in the response:
Customizing Response Keys
You can customize the response keys by creating a new instance with custom keys:
Or use the helper function with configuration:
Array Messages
You can pass arrays of messages:
This will include both message (first message) and messages (all messages) in the response:
โ๏ธ Configuration
Publish the configuration file:
This will create config/api-response.php:
๐ Response Structure
Success Response
Error Response
Paginated Response
๐ฏ Available Methods
Core Methods
response($data, $message, $code, $status, $action)- Generic response methodsuccess($data, $message, $code, $status, $action)- Success response (200)error($message, $data, $code, $status, $action)- Error response (400)ok($message, $data, $code, $status, $action)- OK response (200)
HTTP Status Code Methods
created($data, $message, $code, $status, $action)- 201 Createdaccepted($message, $data, $code, $status, $action)- 202 AcceptednoContent($message, $code, $status, $action)- 204 No ContentbadRequest($message, $data, $code, $status, $action)- 400 Bad Requestunauthorized($message, $data, $code, $status, $action)- 401 Unauthorizedforbidden($message, $data, $code, $status, $action)- 403 ForbiddennotFound($message, $data, $code, $status, $action)- 404 Not FoundmethodNotAllowed($message, $data, $code, $status, $action)- 405 Method Not Allowedconflict($message, $data, $code, $status, $action)- 409 Conflictgone($message, $data, $code, $status, $action)- 410 GonelengthRequired($message, $data, $code, $status, $action)- 411 Length RequiredpreconditionFailed($message, $data, $code, $status, $action)- 412 Precondition FailedunprocessableEntity($message, $data, $code, $status, $action)- 422 Unprocessable EntitytooManyRequests($message, $data, $code, $status, $action)- 429 Too Many RequestsinternalServerError($message, $data, $code, $status, $action)- 500 Internal Server ErrorbadGateway($message, $data, $code, $status, $action)- 502 Bad GatewayserviceUnavailable($message, $data, $code, $status, $action)- 503 Service UnavailablegatewayTimeout($message, $data, $code, $status, $action)- 504 Gateway TimeoutnotImplemented($message, $data, $code, $status, $action)- 501 Not Implemented
๐ง Examples
Controller Example
Validation Error Example
Custom Response Example
๐ Requirements
- PHP >= 8.2
- Laravel >= 11.0 or Laravel >= 12.0
๐งช Testing
The package comes with a comprehensive test suite covering all functionality:
Test Coverage
The test suite includes:
- โ 40+ test cases covering all response methods
- โ All HTTP status codes (200, 201, 400, 401, 403, 404, 422, 500, etc.)
- โ Custom response keys and configurations
- โ Pagination handling
- โ Array messages support
- โ ServiceProvider registration
- โ Helper function availability
- โ Edge cases (null data, null messages, disabled status key)
๐ License
This package is open-sourced software licensed under the MIT license.
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ง Support
For issues, questions, or suggestions, please open an issue on GitHub.
All versions of laravel-api-response with dependencies
illuminate/support Version ^11.0|^12.0
illuminate/http Version ^11.0|^12.0