-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3748716
commit 6dc652e
Showing
3 changed files
with
50 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Laravel Api Response | ||
|
||
## Laravel package for easy formatted api response | ||
|
||
**Installation** | ||
|
||
```bash | ||
composer require wamesk/laravel-api-response | ||
``` | ||
|
||
**Usage** | ||
|
||
For basic response use class and call response() function and pass status code needed *(default 200)*. | ||
|
||
```php | ||
ApiResponse::response(201); | ||
``` | ||
|
||
You can also pass message in your response by adding `message()` function before response function. | ||
|
||
```php | ||
ApiResponse::message('Hello')->response(201); | ||
``` | ||
|
||
You can pass internal code using `message()` function that helps you find of response in case of error. | ||
|
||
```php | ||
ApiResponse::code('1.2.1)->message('Hello')->response(201); | ||
``` | ||
|
||
You can pass data using `data()` function. | ||
|
||
```php | ||
ApiResponse::data(['id' => 1, 'name' => 'Jhon Jhonson'])->code('1.2.1)->message('Hello')->response(201); | ||
``` | ||
|
||
In case you need pagination in your api you can use `collection()` function instead of `data()` function. | ||
You can use this function by passing paginated data, and you can also pass Resource for better data formatting *(Resource is not required)* | ||
|
||
```php | ||
$users = User::paginate(10); | ||
ApiResponse::collection($users, UserResource::class)->code('1.2.1)->message('Hello')->response(201); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters