Download the PHP package zerkxubas/api-response-laravel without Composer
On this page you can find all versions of the php package zerkxubas/api-response-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zerkxubas/api-response-laravel
More information about zerkxubas/api-response-laravel
Files in zerkxubas/api-response-laravel
Package api-response-laravel
Short Description This package can be usefull to structure our api response in laravel api projects, its simple and easy to use.
License MIT
Informations about the package api-response-laravel
API Response Laravel Package
This package provides a structured way to handle API responses in Laravel applications. It includes predefined status codes and a middleware to enforce JSON requests.
NOTE suitable for Laravel v11+
Installation
You can install the package via composer:
Publish Configuration
To publish the configuration file, run the following command:
This will create a config/apiresponse.php file in your project where you can customize the package settings.
Usages
Status Codes
The package includes a set of predefined status codes which can be accessed as constants:
Middleware
The package provides a middleware to ensure that all API requests expect a JSON response. To use register it in your bootstrap/app.php file.
Using ApiResponseController
To use the ApiResponseController
provided by this package, you can extend it in your own controllers. This will allow you to use the standardized API response methods.
More Example SendResponse
More Example SendErrorResponse
Currently Supported Status Codes & Usages
-
200
-
201
-
202
-
400
-
401
-
403
-
404
- 500
Customizing the API Response Implementation
You can customize the API response structure by specifying your own implementation of the ApiResponseInterface
in the config/apiresponse.php
configuration file.
At First, create your custom class implementing ApiResponseInterface
:
Then, update the config/apiresponse.php
file to use your custom class:
License
- Open Source, free to use & distribute.