Easy Response allows you to create REST Callbacks in an easy way. This package has 3 ways to create callbacks which you can use what you want. But if it's suitable for you, the helpers will be more easy and clean.
This package follows PSR-2 and PSR-4 standards.
You can install the package via composer:
composer require neography7/easy-responseThere are three ways to use this package but using it with the helpers is recommended.
easySuccess( message, title = null, data = null);easySuccess(
message: 'Test message',
title: 'Test Title',
data: [
"key" => "value"
]
);or like this
easySuccess('Test message', 'Test Title', [ "key" => "value" ]);easyError( message, title = null, code = null, data = null);easyError(
message: 'Test message',
title: 'Test Title',
code: 400,
data: [
"key" => "value"
]
);or like this
easyError('Test message', 'Test Title', 400, [ "key" => "value" ]);Firstly import the class, then create an instance.
use Neography7\EasyResponse\EasyResponse;
$callback = new EasyResponse;
You can add message, title, success, code, data or add custom key with chaining methods.
$callback->title("Title")
->message("Message")
->success("true")
->response();
The response method is going to make it all together into an array then it responds as a json callback. If success is given as true, the response code will be 200. Additionally, you can add data, code, and custom key-value with the chaining methods.
$callback->title("Error Title")
->message("Error message.")
->success("false")
->code(404)
->data["key" => value]
->addKey("key", value)
->response();
If you want to remove the key that you added, you can use this method.
$callback->removeKey("key");
Firstly import the class that initializes EasyResponse, then call the success or error method that you want to use.
use Neography7\EasyResponse\EA;
$callbackSuccess = EA::success($message, $title = null);
$callbackError = EA::error($message, $title = null, $code = null);
You must to call response method after use.
$callback EA::success("Message", "Title")->response();
I recommend testbench with "nunomaduro/collision" for testing.
php vendor/bin/testbench package:test- The package were created
- More helpers function will be added
- Initial callbacks messages and their translations will be added
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.