Laravel API Respond is a package designed to simplify the process of generating JSON responses in Laravel applications. It provides a convenient way to structure responses with consistent keys and formats, making API development more efficient.
You can install the package via Composer by running the following command:
composer require hassankerdash/laravel-api-respond
After installation, you can use the Respond
service provided by the package to generate JSON responses in your Laravel controllers or services.
// Generate a successful response
return respond()->success(['key' => 'value'], 'Operation completed successfully');
// Generate an error response
return respond()->error('Bad request');
respond()->error('Bad request')->throwResponse();
The Respond
service provides the following methods for generating JSON responses:
success($data, $message = null, $code = 200, $status = true)
: Generate a successful response.error($message, $data = null, $code = 400, $status = false)
: Generate an error response.ok($data, $message = null, $code = 200, $status = true)
: Generate a response indicating success with status code 200.created($data, $message = null, $code = 201, $status = true)
: Generate a response indicating successful resource creation.accepted($data, $message = null, $code = 202, $status = true)
: Generate a response indicating that the request has been accepted for processing.noContent($message = null, $code = 204, $status = true)
: Generate a response with no content.badRequest($message, $data = null, $code = 400, $status = false)
: Generate a response indicating a bad request.notFound($message, $data = null, $code = 404, $status = false)
: Generate a response indicating that the requested resource was not found.methodNotAllowed($message, $data = null, $code = 405, $status = false)
: Generate a response indicating that the request method is not allowed.conflict($message, $data = null, $code = 409, $status = false)
: Generate a response indicating a conflict....
(and more)
This package is open-source software licensed under the MIT license.
Contributions are welcome! Feel free to submit issues or pull requests on GitHub.
For any questions or support, please contact Hassan Kerdash via GitHub Issues.
See the CHANGELOG.md file for details on changes.
This package follows Semantic Versioning.
If you discover a security vulnerability within this package, please send an e-mail to Hassan Kerdash via kerdash@gmail.com. All security vulnerabilities will be promptly addressed.
Special thanks to all contributors and the Laravel community.
Laravel, API, Respond, JSON, Response, Package
Laravel, API, Respond, JSON, Response, Package