Download the PHP package doliveira/laravel-api-response-builder without Composer
On this page you can find all versions of the php package doliveira/laravel-api-response-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download doliveira/laravel-api-response-builder
More information about doliveira/laravel-api-response-builder
Files in doliveira/laravel-api-response-builder
Package laravel-api-response-builder
Short Description A Laravel package designed to simplify the creation of structured and formatted API responses (JSON, XML) with custom status codes, messages, and data.
License MIT
Homepage https://github.com/DaniloWA/laravel-api-response-builder
Informations about the package laravel-api-response-builder
Laravel API Response Builder
Laravel API Response Builder is a Laravel package designed to simplify the creation of structured and formatted API responses (JSON, XML) with customizable status codes, messages, and data. This package provides a flexible way to handle API responses, including error handling, logging, and various configuration options.
Features
- Structured Responses: Define custom response structures for consistency.
- Format Options: Choose between JSON and XML response formats.
- Logging: Log requests and responses for debugging and auditing.
- Compression: Optionally compress responses to reduce payload size.
- Error Handling: Include detailed error messages for debugging.
Installation
To install the package, run the following command:
Configuration
After installing the package, publish the configuration file using the following command:
This will create a config/laravel-api-response-builder.php
file where you can customize the package settings.
Configuration Options
Here's a brief overview of the available configuration options:
default_format
: The default format for responses ('json'
or'xml'
).json_options
: Options for JSON encoding (e.g.,JSON_UNESCAPED_SLASHES
).xml_root_element
: The default root element for XML responses.default_status_code
: The default HTTP status code for responses.detailed_errors
: Whether to include detailed error messages for debugging.wrap_data
: Whether to wrap response data in an additional'data'
key.default_locale
: The default locale for custom messages.default_response_language
: The default language for responses ('en'
or'pt'
).compress_responses
: Whether to compress responses.log_responses
: Whether to log responses.logging_level
: The level of detail for logging responses.api_key_header
: The name of the header used for API keys.custom_response_structure
: Define a custom structure for responses.debug_mode
: Enable or disable debug mode.log_requests
: Whether to log requests.log_response_time
: Whether to log response times.
Usage
JSON Responses
Success Response
Error Response
XML Responses
To create XML responses, use the XmlResponse
class:
Error Handling
The package allows you to include detailed error messages for debugging. By default, this is disabled in production environments:
You can enable detailed error messages for debugging purposes by setting 'detailed_errors'
to true
in the configuration.
Examples
Success JSON Response
Error JSON Response
Success XML Response
Error XML Response
Logging
The package can log requests, responses, and response times. Configure logging settings in config/laravel-api-response-builder.php
:
Contributing
If you want to contribute to the development of this package, please fork the repository and submit a pull request.
License
This package is licensed under the MIT License.
Contact
For any questions or feedback, please contact:
- Danilo Oliveira: [email protected]
- Website: daniloo.dev
Note: The Package is currently under construction and may be updated further. As this is an early release, there may be bugs or incomplete features. We appreciate your understanding and feedback as we continue to improve the package.