Easy API responses.
Installs: 33
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/gouravbajaj0210/api
This package is not auto-updated.
Last update: 2025-12-22 06:12:34 UTC
README
Installation
First, pull in the package through Composer.
"require": { "gouravbajaj0210/api": "dev-master" }, "repositories": [ { "type": "git", "url": "https://gouravbajaj0210@bitbucket.org/gouravbajaj0210/api-package.git" } ],
And then, include the service provider within config/app.php.
'providers' => [ gouravbajaj0210\api\ApiProvider::class ];
And, for convenience, add a facade alias to this same file at the bottom:
'aliases' => [ 'api' => gouravbajaj0210\api\ApiFacade::class ];
Publish the configurations by running this artisan command:
php artisan vendor:publish
Usage
api::success(['data'=>'random data'])api::notFound(['errorMsg'=> 'user not found'])api::notAuth(['errorMsg'=> 'user not authorized'])api::notValid(['errorMsg'=> 'email field is required'])api::serverError(['errorMsg'=> 'soemthing went wrong'])
Alternatively, you may reference the api() helper function, instead of the facade. Here's an example:
api()->success(['data' => 'some data']);
api()->notFound(['errorMsg' => 'something nto found']);
Or, for a success API response, just do: api(['data' => 'Some message']);.
Method chaining
You can make use of method chaining:
#!php
api()->data(['data'=> 'my data'])->statusCode(201)->success();
api()->json()->notFound();