Download the PHP package ars/api-responder-laravel without Composer
On this page you can find all versions of the php package ars/api-responder-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ars/api-responder-laravel
More information about ars/api-responder-laravel
Files in ars/api-responder-laravel
Package api-responder-laravel
Short Description A library to simplify the creation of standardized API responses.
License MIT
Homepage https://github.com/alireza2000sajedi/api-responder-laravel
Informations about the package api-responder-laravel
API Responder - Laravel Response
ars/api-responder-laravel is a Laravel package designed to streamline the creation of standardized API responses. It provides a user-friendly interface for managing API responses, including common status codes and error messages, making API development in Laravel more efficient and consistent.
Features
- Standardized response structure for successful and error responses.
- Customizable response data with support for links and metadata.
- Easy integration with Laravel through a facade and service provider.
Installation
You can install the library via Composer. Run the following command:
Usage
Basic Response
You can use the Responder facade to create standardized API responses.
Example:
Additional Methods
ok(array $data)
: Return a response 200.respond(array $data)
: Prepare and return a response.setData(array $data)
: Set the response data.setMessage(string $message)
: Set a message for the response.appendData(array $data)
: Append additional data to the response.setErrorCode(mixed $errorCode)
: Set an error code for the response.setStatusCode(int $statusCode)
: Set the HTTP status code for the response.setLinks(array $links)
: Set pagination or other links.setMeta(array $meta)
: Set metadata for the response.
Messages
The library supports various status messages:
If a message key is provided, use setMessage(string $message)
to set the message.
- success: "Operation successful!"
- error: "Operation encountered an error!"
- validation_error: "Validation failed!"
- internal_error: "Internal server error!"
- created: "has been created."
- updated: "has been updated."
- deleted: "has been deleted."
- send: "has been sent."
- before_posted: "has already been posted."
- expire: "has expired."
- not_valid: "is not valid."
- used: "has already been used."
- re_send: "has been resent."
- unauthenticated: "User is not authenticated!"
- unauthorized: "User is not authorized to access this resource!"
- not_found: "Resource not found!"
- bad_request: "Bad request!"
- to_many_request: "Too many requests!"
Contributing
Contributions are welcome! Please adhere to the following guidelines:
- Fork the repository.
- Create a feature branch (git checkout -b feature/my-new-feature).
- Commit your changes (git commit -am 'Add new feature').
- Push to the branch (git push origin feature/my-new-feature).
- Open a Pull Request.
License
This library is licensed under the MIT License.
Contact
For support or questions, please open an issue on GitHub.