antare74 / response-formatter
This package is used to format the response in a standardized way as json format to help the frontend to understand the response and handle the API response easily.
Fund package maintenance!
antare74] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g.
[user1
user2
Installs: 3 594
Dependents: 0
Suggesters: 0
Security: 0
Stars: 17
Watchers: 1
Forks: 1
Open Issues: 1
Requires
- php: ^7.0.33|^8.0
This package is auto-updated.
Last update: 2024-10-20 08:17:48 UTC
README
Laravel Response Formatter
I created this package to make it easier to format the response from a controller. I have used this package in my projects and I hope you enjoy it!
📝 Table of Contents
🧐 About
It is a simple package that allows you to format your response in a consistent way. This might be useful for your API, or for your front-end.
🏁 Getting Started
These instructions will help you get started with your project.
Prerequisites
What things you need to install the software and how to install them.
composer
Laravel Version: >= 5.8
Installing
A step by step series of examples that tell you how to get a development env running.
composer require antare74/response-formatter
🎈 Usage
Example Usage.
<?php
use Illuminate\Support\Facades\Route;
use Antare74\ResponseFormatter\Format;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/success', function () {
return Format::success([
'name' => 'Antare74',
'age' => '74',
'address' => 'Jakarta',
], 'Success Message');
});
Route::get('/error', function () {
return Format::error([
'my_error_data' => 'Error Message',
], 'Error Message', 500);
});
Example Success Response.
{
"meta": {
"code": 200,
"status": "success",
"message": "Success Message",
"is_paginated": false
},
"pagination": [
],
"data": {
"name": "Antare74",
"age": "74",
"address": "Jakarta"
}
}
Example Error Response.
{
"meta": {
"code": 500,
"status": "error",
"message": "Error Message",
"is_paginated": false
},
"data": {
"my_error_data": "Error Message"
}
}
✍️ Authors
- @antare74 - IDK
See also the list of contributors who participated in this project.
🎉 Acknowledgements
- Find on Packagist: https://packagist.org/packages/antare74/response-formatter
- References format: https://github.com/belajarkoding/laravel-response-formatter/blob/master/ResponseFormatter.php